Haskell synonym definition -
could explain me following synonim means , how read it:
type tcm = errort string (statet myenv io)
what able understand till now:
we introduce new name type , call tcm , has parameter a
we have value constructor errort (what makes errort?) takes 3 arguments: string, (statet myenv io) , a
(statet myenv io) - here have value constructor statet , args myenv , io. type makes?
am right? explain me how works? responses.
edit: maybe me this. have sth following function in program evaluate integer:
ms_exp :: exp -> tcm () ms_exp (eint integer) = return integer
and have such error:
couldn't match expected type `()' actual type `integer'
any hints?
well,
errort
type hada
type parameter, if wished, specialize it, is, make typetype tcmint = errort string (statet myenv io) int
however, can leave type parameter, did in example.
no,
errort
not value constructor, type constructor. makes element oferrort
? well, depends onerrort
is. suppose control.monad.error, , said is constructedrunerrort
function.again,
statet
not value constructor, type constructor (creatednewtype
keyword acoording this). can seenewtype state s a
,state
type constructors expects 2 type names construct type, code passesmyenv
,io
, yieldingstatet myenv io
type.
to update: function expects inject element of ()
tcm
monad doing return ()
while return integer
. need either return ()
or change type of ms_exp
exp -> tcm integer
.
Comments
Post a Comment