Skip to content

Instantly share code, notes, and snippets.

@aratama
Created December 13, 2016 09:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aratama/fa1c2b51753c0dd15ff162b36b9bd48d to your computer and use it in GitHub Desktop.
Save aratama/fa1c2b51753c0dd15ff162b36b9bd48d to your computer and use it in GitHub Desktop.
Type level boolean values
module Main where
import Prelude (Unit)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Symbol (SProxy(SProxy), reflectSymbol)
data True
data False
class Show a (b :: Symbol) | a -> b
instance showTrue :: Show True "True"
instance showFalse :: Show False "False"
class Not a b | a -> b
instance notTrue :: Not True False
instance notFalse :: Not False True
class Xor a b c | a b -> c
instance xorTT :: Xor True True False
instance xorFT :: Xor False True True
instance xorTF :: Xor True False True
instance xorFF :: Xor False False False
foo :: forall a. Show True a => SProxy a
foo = SProxy
bar :: forall a b. (Not True a, Show a b) => SProxy b
bar = SProxy
xor :: forall a b c. (Xor True False a, Not a b, Show b c) => SProxy c
xor = SProxy
main :: forall e. Eff (console :: CONSOLE | e) Unit
main = log (reflectSymbol xor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment