質問

I'm programming a Lispy PDDL parser for the AI Planning class at Coursera.

How can I define a Lispy datatype in Haskell?

役に立ちましたか?

他のヒント

It looks Lispy, doesn't it?

{-# 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

The result of running main:

(define x 10 (print hello) ())
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top