Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing <*> with ap for maybe results in an exception #189

Open
luminusian opened this issue Feb 22, 2017 · 0 comments
Open

replacing <*> with ap for maybe results in an exception #189

luminusian opened this issue Feb 22, 2017 · 0 comments

Comments

@luminusian
Copy link

(<*>) = ap, although more efficient implementations may exist
https://wiki.haskell.org/Functor-Applicative-Monad_Proposal#Compatibility_issues

However,

(m/<*> (m/<$> (m/curry 2 +) (maybe/just 1)) (maybe/just 2))
=> #<Just 3>
(m/ap (m/<$> (m/curry 2 +) (maybe/just 1)) (maybe/just 2))
CompilerException java.lang.ClassCastException: cats.monad.maybe.Just cannot be cast to clojure.lang.IFn, compiling:
ap                :: (Monad m) => m (a -> b) -> m a -> m b
ap m1 m2          = do { x1 <- m1; x2 <- m2; return (x1 x2) }

https://hackage.haskell.org/package/base-4.9.1.0/docs/src/GHC.Base.html#ap

(defn ap
  [m1 m2]
  (m/mlet [x1 m1
           x2 m2]
          (m/return (x1 x2))))

(ap (m/<$> (m/curry 2 +) (maybe/just 1)) (maybe/just 2))
=> #<Just 3>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant