Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Last active June 25, 2022 22:37
Show Gist options
  • Select an option

  • Save ramirez7/5df3e61fc05056571ce0fdb694aa22d2 to your computer and use it in GitHub Desktop.

Select an option

Save ramirez7/5df3e61fc05056571ce0fdb694aa22d2 to your computer and use it in GitHub Desktop.
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-
Here are the GHC/singletons versions I used to run this:
$ nix-shell -p haskell.compiler.ghc921 --command 'cabal repl -b "singletons == 3.0.1" -b "singletons-base == 3.1"'
-}
module SingletonBool where
import Data.Singletons
import Prelude.Singletons
import Data.Kind
-- You might as well mark this as injective since it is:
type family F (b :: Bool) = (r :: Type) | r -> b where
F True = Int
F False = Char
f1 :: forall (x :: Bool). (Sing x -> F x) -> Sing x -> F x
f1 = ($)
f2 :: Sing x -> F x
f2 = \case
STrue -> 2
SFalse -> 'b'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment