ekmett / free

free monads
http://hackage.haskell.org/package/free
Other
158 stars 65 forks source link

Free Applicative+Monad+Alternative/MonadPlus #8

Closed ghost closed 11 years ago

ghost commented 11 years ago

When trying to make a simple schema EDSL, I inadvertently recreated the Control.Applicative.Free part of this library. When someone directed me to this library, I was able to streamline mine, adding the equivalents of lift and runAp.

However, I went a bit further in my module: FList is a free Applicative functor, Monad, and Alternative functor. The interface barely changes, only requiring the result of runFList to be monadic as well. runFList also takes an additional sum function, so that the user can supply their own semantics for <|>.

Is there a chance the free library will be extended, so I can use that instead of my attempt to have free Alternative functors (plus Monad)?

ekmett commented 11 years ago

Hrmm. the issue i'd have would be ensuring the correct semantics with regards to (<|>) and I don't think its possible to do so.

Right now all of the free constructions we export are truly free.

However, the fact that there are two competing semantics for (<|>) indicate to me that I probably cannot construct something that is truly free with regards to that action.

I'm somewhat loathe to introduce a non-free construction in this package.

ghost commented 11 years ago

I understand there is a general problem of having different semantics for (<|>)/mplus, but I would think this stops being a problem when runFList takes a function forall a. [g a] -> g a to specify it.

The semantics provided by the user can't violate the Alternative laws, because associativity and identity are enforced by my module. Meanwhile, the signature of the user-supplied semantics seems free enough to me to allow any desired semantics, so both Left Catch and Left Distribution should be possible.

What problem am I missing here?