我正在为 Coursera 的 AI 规划课程编写一个 Lispy PDDL 解析器。
如何在 Haskell 中定义 Lispy 数据类型?
它看起来很 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) ())
我的 Lispy PDDL 解析器:
https://dl.dropbox.com/u/46434672/Code/LispyPddlParser.hs
DWR-operators.txt 文件:
https://spark-public.s3.amazonaws.com/aiplan/resources/DWR-operators.txt