You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否直接编译论文中的原始Haskell代码?求可行方法

How to Compile the Original Paper Code Without Modifications

Absolutely, you can compile the original code from the paper without altering any part of it—you just need to add the missing foundational definitions and enable the right GHC language extensions. Here's how to do it:

First, let's restate the original code from Listing 1 that you want to preserve exactly as-is:

class (QUALITIES affordance physicalEndurant, PHYSICAL_ENDURANTS physicalEndurant) => AFFORDANCES affordance physicalEndurant
data PHYSICAL_OBJECTS step => Climbability step = Climbability step
instance QUALITIES Climbability Step
instance AFFORDANCES Climbability Step

This snippet relies on implicit definitions the paper doesn't show, plus specific Haskell extensions. Follow these steps to make it compile:

1. Enable Required Language Extensions

Add this pragma at the very top of your file. These extensions support the syntax used in the paper's code:

{-# LANGUAGE MultiParamTypeClasses, DatatypeContexts, FlexibleInstances #-}
  • MultiParamTypeClasses: Lets you define classes with multiple type parameters (like QUALITIES and AFFORDANCES).
  • DatatypeContexts: Allows the constraint on the Climbability data type (this extension is deprecated in modern GHC, but it still functions and is necessary to keep the original code unmodified).
  • FlexibleInstances: Enables instances like QUALITIES Climbability Step where type parameters don't follow the strict pattern of the class definition.

2. Add Missing Foundational Definitions

These are the implicit types and classes the paper assumes exist—they don't modify the original Listing 1 code, just provide its dependencies:

-- Define the Step type referenced in the instances
data Step = Step

-- Define the base classes the original code depends on
class PHYSICAL_ENDURANTS a where
class PHYSICAL_OBJECTS a where
class QUALITIES a b where

-- Add required instances to satisfy constraints in Listing 1
instance PHYSICAL_ENDURANTS Step where
instance PHYSICAL_OBJECTS Step where

3. Include the Original Listing 1 Code

Paste the unmodified Listing 1 code right after the above definitions. The full file will compile successfully with GHC.

Why This Works

The paper's Listing 1 is a condensed snippet that skips over foundational setup code. By adding those missing pieces and enabling the necessary extensions, you're providing the exact context the original code needs—without changing any part of the code from the paper.

If you wanted to avoid the deprecated DatatypeContexts extension, you'd have to adjust the Climbability data type definition, but since your goal is to keep the original code untouched, using the deprecated extension is the valid approach here.

内容的提问来源于stack exchange,提问作者Patrick Browne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:22:18