ekmett / free

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

Simplify the applicative instance of Free #199

Open ianliu opened 3 years ago

ianliu commented 3 years ago

Is it possible to simplify the following two lines

https://github.com/ekmett/free/blob/a06c37ff51cc6e1a008b5d6e5f5c13c80edc67a0/src/Control/Monad/Free.hs#L222-L223

to this?

  (Pure a) <*> b = fmap a b

I'm still learning Haskell and I was trying to implement the Free monad myself and came here to compare my implementation with yours; so I apologize in advance if this "issue" is just plain bogus.

Thanks, Ian

RyanGlScott commented 3 years ago

Yes, those are equivalent as far as I can tell.

Icelandjack commented 3 years ago

Yes and a lot clearer, this part of the Applicative docs becomes relevant

As a consequence of these laws, the Functor instance for f will satisfy

fmap f x = pure f <*> x