Define Haskell type with multiple contained types -
my goal replace signature like
execute :: [instruction] -> state -> pointer -> state
with
execute :: program -> state
i created type synonym
type program = [instruction] -> state -> pointer
when define implementation (e.g. execute [] s _ = s
), receive following compile error:
couldn't match expected type ‘state -> pointer -> state’ actual type ‘[int]’ equation(s) ‘execute’ have 3 arguments, type ‘program -> state’ has 1
without replacing [instruction] -> state -> pointer
program
, compiles. appears attempt match program
type first argument. there way match program
type on first 3 arguments?
your type synonym function type (of 2 arguments, uncurried). when have function
fun :: programm -> state fun p = ...
that p
function needs 2 arguments, namely 1 [instruction]
, 1 state
produce pointer
. function, not needed instructions nor state. (and no pointer, if can computed instructions , state, why have parameter original function...)
what seem want packing 3 arguments one. tuple therefore:
type program = ([instruction], state, pointer)
or use record syntax:
data program = program { instructionsof :: [instruction], stateof :: state, pointerof :: pointer }
then code comes closer english:
fun :: program -> state fun program = run (instructionsof program) -- or whatever
Comments
Post a Comment