Skip to content

Instantly share code, notes, and snippets.

@timjb
Last active April 2, 2016 13:59
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 timjb/22089834de020bb3e64d300aa07aa473 to your computer and use it in GitHub Desktop.
Save timjb/22089834de020bb3e64d300aa07aa473 to your computer and use it in GitHub Desktop.
module PatternSynonymsImport where
-- one can use either an unqualified import
import PatternSynonymsTest
-- alternatively one can use explicit imports (this requires enabling the
-- PatternSynonyms language extension):
-- import PatternSynonymsTest (Option(..), pattern None)
maybeToOption :: Maybe a -> Option a
maybeToOption Nothing = None
maybeToOption (Just a) = Some a
optionToMaybe :: Option a -> Maybe a
optionToMaybe None = Nothing
optionToMaybe (Some a) = Just a
{-# LANGUAGE PatternSynonyms #-}
module PatternSynonymsTest
( Option(..)
, pattern None
) where
data Option a
= Some a
| NoneMsg String
deriving (Show, Eq)
pattern None <- NoneMsg _ where
None = NoneMsg ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment