Created
May 21, 2013 05:26
-
-
Save khibino/5617647 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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