haskell - Deceptively not-as-simple-as-I-thought typing -
in process of writing interpreter in haskell separate, simple programming language - find myself butting head against wall learn typing in haskell.
i have 2 custom data types
data expr = var var | nume int | nile | conse expr expr | plus expr expr | minus expr expr | times expr expr | div expr expr | equal expr expr | less expr expr | greater expr expr | not expr | isnum expr | , expr expr | or expr expr | head expr | tail expr | call string deriving (show, read) data val = num int | nil | cons val val deriving (eq, show, read)
and i'm starting write cases interpreting these options, function interpret_expr
interpret_expr :: vars -> expr -> val interpret_expr vars@(vars b c d) (nume integer) = integer
but complains couldn't match expected type 'val' actual type 'int' in expression 'integer'. change silly
interpret_expr :: vars -> expr -> val interpret_expr vars@(vars b c d) (nume 'a') = 'a'
it complains @ 'a' can't match expected type 'int' actual type 'char'. wants int?????? don't know say, thought simple providing nume variable figure integer. doing wrong?
in first case returning int
function declared return val
. definition of val
looks want return num integer
here.
in second case problem in pattern matching. (nume 'a')
error because nume
defined nume int
, must followed int
, not char
.
Comments
Post a Comment