Domanda

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

How can I define a Lispy datatype in Haskell?

È stato utile?

Altri suggerimenti

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) ())
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top