Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created March 9, 2014 23:07
Show Gist options
  • Select an option

  • Save tonymorris/9456369 to your computer and use it in GitHub Desktop.

Select an option

Save tonymorris/9456369 to your computer and use it in GitHub Desktop.
FirstNothing
module FirstNothing where
-- $setup
-- >>> import Test.QuickCheck
-- >>> instance Arbitrary a => Arbitrary (FirstNothing a) where arbitrary = fmap FirstNothing arbitrary
newtype FirstNothing a =
FirstNothing (Maybe a)
deriving (Eq, Show)
class Semigroup a where
(<>) ::
a
-> a
-> a
-- |
--
-- prop> ((x <> y) <> z) == (x <> (y <> (z :: FirstNothing Int)))
instance Semigroup (FirstNothing a) where
FirstNothing Nothing <> _ =
FirstNothing Nothing
FirstNothing (Just x) <> FirstNothing (Just _) =
FirstNothing (Just x)
FirstNothing (Just _) <> FirstNothing Nothing =
FirstNothing Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment