如何在Haskell中定义Lispy数据类型?

时间:2013-02-17 05:01:14

标签: haskell lisp gadt

我正在为Coursera的AI Planning课程编写一个Lispy PDDL解析器。

如何在Haskell中定义Lispy数据类型?

2 个答案:

答案 0 :(得分:2)

它看起来像Lispy,不是吗?

{-# LANGUAGE FlexibleInstances #-}

import Data.List

data S s = T s | S [S s] deriving (Eq)

instance Show (S String) where
 show (T s) = s
 show (S list) = "(" ++ (intercalate " " $ map show list) ++ ")"

sExpr = S [T "define",T "x",T "10",S [T "print",T "hello"],S []]

main = do
 putStrLn $ show sExpr

运行main的结果:

(define x 10 (print hello) ())

答案 1 :(得分:0)