Created
September 11, 2019 12:14
-
-
Save Elvecent/2b7cb31d6ffab9aec7623244d793d086 to your computer and use it in GitHub Desktop.
Deep Pure Fun
This file contains 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 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