Skip to content

Instantly share code, notes, and snippets.

@Javran

Javran/z.hs Secret

Created September 27, 2020 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Javran/aef0895f58048e1234b883afc8623f32 to your computer and use it in GitHub Desktop.
Save Javran/aef0895f58048e1234b883afc8623f32 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ExplicitForAll, TypeApplications, ScopedTypeVariables #-}
import Control.Monad.Except
import Data.Coerce
import Data.Functor.Identity
maybeToEither :: e -> Maybe a -> Either e a
maybeToEither v m = case m of
Nothing -> Left v
Just r -> Right r
m2e :: forall e a. e -> Maybe a -> Except e a
m2e = coerce (maybeToEither @e @a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment