Skip to content

Instantly share code, notes, and snippets.

@markus1189
Created January 30, 2016 14:36
Show Gist options
  • Save markus1189/ed5e5ef8fdc99ab4acfb to your computer and use it in GitHub Desktop.
Save markus1189/ed5e5ef8fdc99ab4acfb to your computer and use it in GitHub Desktop.
Haskell LightSwitch
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
module LightSwitch where
data Power = On | Off
type family Toggle (a :: Power) where
Toggle On = Off
Toggle Off = On
data Switch (a :: Power) where
Switch :: Switch a
on :: Switch On
on = Switch
off :: Switch Off
off = Switch
toggle :: Switch a -> Switch (Toggle a)
toggle Switch = Switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment