[Haskell-beginners] Typeclasses vs. Data

Thomas haskell at phirho.com
Thu Jul 21 00:26:19 CEST 2011


Hello David!

Thank you for taking the time.
Here is a complete fragment that shows the error:

data Expression = Null | Num Int | Id String | List [Expression]
      deriving (Eq, Show)

cdr :: Expression -> Expression
cdr (List []) = error "cdr Null !"
cdr (List (_:[])) = Null
cdr (List (l:ls)) = List ls

car :: Expression -> Expression
car (List l) = head l
car n = error (show n)

isNull Null = True
isNull _ = False

eval e k = case (car e) of
      (Id "begin") ->  eval_begin (cdr e) k

eval_begin e k = eval (car e) (if isNull (cdr e) then k else (BeginCont 
k (cdr e)))

class Continuation a where
    resume :: a -> Expression -> Expression

data BeginCont a = BeginCont a Expression deriving (Show)
instance (Continuation a) => Continuation (BeginCont a) where
   resume (BeginCont k es) v = eval_begin es k

Regards,
Thomas



On 21.07.2011 00:18, David Place wrote:
> On Jul 20, 2011, at 5:58 PM, Thomas wrote:
>
>> class Continuation a where
>>    resume :: a ->  Expression ->  Expression
>>
>> data BeginCont a = BeginCont a Expression deriving (Show)
>> instance (Continuation a) =>  Continuation (BeginCont a) where
>>   resume (BeginCont k es) v = eval_begin es k
>
> I think we need to know the definition of Expression.  if define it with a dummy type
>
> eval_begin a b = a
> type Expression = Int
>
> this code fragment compiles.  Would you send a code fragment that will yield the error?
> ____________________
> David Place
> Owner, Panpipes Ho! LLC
> http://panpipesho.com
> d at vidplace.com
>
>




More information about the Beginners mailing list