haskell-numerics / random-fu

A suite of Haskell libraries for representing, manipulating, and sampling random variables
42 stars 21 forks source link

MonadRandom is not Functor? #27

Closed yongqli closed 9 years ago

yongqli commented 9 years ago

I could be wrong, but it seems that a MonadRandom is not necessarily a Functor, which causes problems:

Could not deduce (Functor m) arising from a use of ‘_1’
from the context (MonadRandom m)
idontgetoutmuch commented 9 years ago

It's a bit hard to say what is going on with this much information but it seems the compiler is telling you that you have only specified that m must be MonadRandom and you are trying to use it as a Functor. If you wish to use it as a Functor then you must say so by adding Functor m to the context. I don't think this is anything to do with random-fu but if you think otherwise perhaps you can provide some rationale?

yongqli commented 9 years ago

Shouldn't every MonadRandom be a Functor automatically since every Monad is an Applicative and is thus also a Functor?

idontgetoutmuch commented 9 years ago

Currently something can be a monad without being applicative (in the Haskell sense) - see http://www.haskell.org/haskellwiki/Functor-Applicative-Monad_Proposal. Also it need not be a functor; that is the Monad class is defined like this; clearly it has to be a functor (after all a monad is functor and two natural transformations) in the mathematical sense. Once the proposed change goes ahead then you will not need to add Functor to your constraints but currently you do. I really don't think this has anything to do with random-fu as MonadRandom is a Monad with extra capabilities beyond what is in the Monad class. I am going to close this ticket but if you feel this is unsatisfactory then please let me know your rationale.

idontgetoutmuch commented 9 years ago

See also http://stackoverflow.com/questions/25622571/how-do-i-make-monadrandom-a-functor?