Created
July 25, 2015 23:57
-
-
Save sshastry/9fc90361204564e1f684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
import Control.Applicative | |
import Data.Maybe | |
import Data.Monoid | |
newtype X a = X { getX :: Maybe a } deriving (Eq, Ord, Read, Show, Functor, Applicative, Monad) | |
instance Monoid a => Monoid (X a) where | |
mempty = X (Just mempty) | |
X (Just x) `mappend` X (Just y) = X (Just (x `mappend` y)) | |
X (Nothing) `mappend` _ = X Nothing | |
_ `mappend` X (Nothing) = X Nothing | |
g = X . Just . Sum | |
xs = map g [1..10] | |
ys = (map g [1..5]) ++ [X Nothing] ++ (map g [6..10]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment