Skip to content

Instantly share code, notes, and snippets.

@Elvecent
Created September 11, 2019 12:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elvecent/2b7cb31d6ffab9aec7623244d793d086 to your computer and use it in GitHub Desktop.
Save Elvecent/2b7cb31d6ffab9aec7623244d793d086 to your computer and use it in GitHub Desktop.
Deep Pure Fun
{-# LANGUAGE TypeApplications, DataKinds, KindSignatures, TypeFamilies, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}
module Main where
import Data.Functor.Compose
import Data.Functor.Identity
import Data.Coerce
data Nat = Zero | Succ Nat
type family WrapCompose (x :: *) where
WrapCompose (f x) = Compose f (WrapCompose x)
WrapCompose x = Identity
class Pure f (n :: Nat) | f -> n where
deepPure :: a -> f a
instance Pure Identity Zero where
deepPure = Identity
instance (Applicative f, Pure g n) => Pure (Compose f g) (Succ n) where
deepPure = Compose . pure . deepPure
veryPure :: forall a b n. (Coercible b (WrapCompose b a), Pure (WrapCompose b) n)
=> a -> b
veryPure x = coerce $ deepPure @(WrapCompose b) x
main :: IO (Maybe Bool)
main = veryPure ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment