Skip to content

Instantly share code, notes, and snippets.

@khibino
Created May 21, 2013 05:26
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 khibino/5617647 to your computer and use it in GitHub Desktop.
Save khibino/5617647 to your computer and use it in GitHub Desktop.
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE IncoherentInstances #-}
module X where
data P a = P
flattenMaybe :: P (Maybe (Maybe a)) -> P (Maybe a)
flattenMaybe P = P
class ProjectableMaybe a b where
flatten :: P a -> P b
instance ProjectableMaybe (Maybe a) b => ProjectableMaybe (Maybe (Maybe a)) b where
flatten = flatten . flattenMaybe
instance ProjectableMaybe (Maybe a) (Maybe a) where
flatten = id
f :: P (Maybe (Maybe (Maybe (Maybe a)))) -> P (Maybe a)
f = flatten
v :: P (Maybe (Maybe (Maybe (Maybe Int))))
v = P
foo :: P (Maybe Int)
foo = flatten v
-- error
-- bar :: P Int
-- bar = flatten foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment