haskell - Restricting monad type in data constructor -
i'm looking create small monadic interpreter in haskell , ran problem ghc complaining me kinds don't match up.
specifically, here declaration data type value:
data value = wrong | num int | fun (value -> monad value) and when compile this, ghc gives following error message:
the first argument of ‘monad’ should have kind ‘* -> *’, ‘value’ has kind ‘*’ in type ‘value -> (monad value)’ in definition of data constructor ‘fun’ in data declaration ‘value’ but monad value of kind *. don't see problem here?
could kindly point me bug i'm not seeing? lot!
p.s. interpreter based on 1 introduced in wadler's paper the essence of functional programming.
essentially, monad expects type constructor takes 1 argument. value type constructor takes no arguments. so, value must have kind * -> * (meaning takes 1 argument) instead of * (meaning takes no arguments).
also, if value did take 1 argument (allowing type check), monad value of kind constraint. because monad of kind (* -> *) -> constraint , in monad value being applied of kind * -> *.
Comments
Post a Comment