문제

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