[Ur] Implementing StateMonad transformer

Sergey Mironov grrwlf at gmail.com
Thu Dec 12 06:16:28 EST 2013


Hi. I tried to implement a StateMonad in UrWeb. I've successfully
compiled it's basic version

https://github.com/grwlf/urweb-monad-state/blob/master/test/Test2.ur

and the advanced one, which operates on top of the transaction monad

https://github.com/grwlf/urweb-monad-state/blob/master/test/Test3.ur

Finally, I've faced an error while trying to move one step further. I
tried to implement a 'monad transformer'. It's goal is to let user
choose the underlying monad. Haskell version allows it by defining
third datatype parameter with kind (Type -> Type). But looks like it
wouldn't work for Ur/Web since UrWeb accepts only Type kinds in this
place (but I may have missed some syntax):

datatype state m st a = State of (st -> m (st * a))

leads to

building test/Test4.exe
urweb -dbms sqlite ./test/Test4
/home/grwlf/proj/urweb-monad-state/test/Test4.ur:6:40: (to 6:41) Wrong kind
Constructor:  m
  Have kind:  Type
    Need kind:  <UNIF:B> -> <UNIF:C>
    Incompatible kinds
    Kind 1:  Type
    Kind 2:  <UNIF:B> -> <UNIF:C>
    make[1]: *** [test/Test4.exe] Ошибка 1
    make[1]: Выход из каталога `/home/grwlf/proj/urweb-monad-state'
    make: *** [.fix-multy1] Ошибка 2

Can we do something to allow this kind of monads?

Regards,
Sergey

PS the project root is https://github.com/grwlf/urweb-monad-state



More information about the Ur mailing list