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

Nesting Just and Identity results in java.lang.ClassCastException. #188

Open
luminusian opened this issue Feb 16, 2017 · 1 comment
Open

Comments

@luminusian
Copy link

In cats,

(m/>>= (identity/identity (maybe/just 0))
       (fn [x]
         (m/return (m/<$> identity x))))
CompilerException java.lang.ClassCastException: cats.monad.maybe.Just cannot be cast to cats.monad.identity.Identity

In Haskell,

*Main> Identity (Just 0) >>= (\x -> return (id <$> x))
Identity (Just 0)
@luminusian
Copy link
Author

luminusian commented Feb 16, 2017

Reordering cond in infer in cats.context seems to resolve the issue.

(defn infer
  "Given an optional value infer its context. If context is already set, it
  is returned as is without any inference operation."
  {:no-doc true}
  ([]
   (when (nil? *context*)
     (throw-illegal-argument "No context is set."))
   *context*)
  ([v]
   (cond
     (satisfies? p/Contextual v)
     (p/-get-context v)
     (not (nil? *context*))
     *context*
     :else
     (throw-illegal-argument
      (str "No context is set and it can not be automatically "
           "resolved from provided value")))))

Now,

(m/>>= (identity/identity (maybe/just 0))
       (fn [x]
         (m/return (m/<$> identity x))))
=> #<Identity #<Just 0>>

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