KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to create my own monad. This is what i wrote: data LeafConType a = LeafCon (a,Int,Int) instance Monad (LeafConType ) where return = LeafCon lc@(LeafCon (t,i,n)) >>= f = if i>=n then lc else f (t,i,n) But this dont work. Ghc says: leafcon.hs:26:1: Occurs check: cannot construct the infinite type: a = (a, Int, Int) When generalising the type(s) for `return' In the instance declaration for `Monad LeafConType' leafcon.hs:27:1: Occurs check: cannot construct the infinite type: a = (a, Int, Int) When generalising the type(s) for `>>=' In the instance declaration for `Monad LeafConType' Whats wrong with that? I want to do calculations while i is lower than n. n should be constants by I don't know yet how to do this correct. It should be some mix of State and Maybe. If you have some advices feel free to share it with me:P
Tags (comma-separated)
Save Edits
Cancel