Last active
July 16, 2021 21:27
-
-
Save evanrelf/ea9d135522fd17676d2f30556f98e367 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 FlexibleInstances #-} | |
{-# LANGUAGE TypeFamilies #-} | |
module Smoosh | |
( Smoosh (..) | |
) | |
where | |
import Control.Monad (join) | |
type family Smooshed a where | |
Smooshed (f (f a)) = Smooshed (f a) | |
Smooshed a = a | |
class Smoosh a where | |
smoosh :: a -> Smooshed a | |
instance {-# OVERLAPPABLE #-} a ~ Smooshed a => Smoosh a where | |
smoosh = id | |
instance (Monad m, Smoosh (m a)) => Smoosh (m (m a)) where | |
smoosh = smoosh . join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment