Skip to content

Instantly share code, notes, and snippets.

@evanrelf
Last active July 16, 2021 21:27
Show Gist options
  • Save evanrelf/ea9d135522fd17676d2f30556f98e367 to your computer and use it in GitHub Desktop.
Save evanrelf/ea9d135522fd17676d2f30556f98e367 to your computer and use it in GitHub Desktop.
{-# 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