Skip to content

Instantly share code, notes, and snippets.

@dminuoso
Created December 8, 2021 20:06
Show Gist options
  • Save dminuoso/6b9181446eaffac9ceb0771a0e013d3b to your computer and use it in GitHub Desktop.
Save dminuoso/6b9181446eaffac9ceb0771a0e013d3b to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
data Mode = Field | Descr
type family Inner mode field where
Inner Field f = f
Inner Descr f = String
data ArgF (f :: Mode) = ArgF
{ field1 :: Inner f Char
, field2 :: Inner f Int
}
someArg :: ArgF Field
someArg = ArgF
{ field1 = 'c'
, field2 = 42 }
argDescr :: ArgF Descr
argDescr = ArgF
{ field1 = "Some field 1"
, field2 = "Another fancy field"
}
type Sel f = forall mode. (ArgF mode -> Inner mode f)
get :: Sel f -> f
get sel = sel someArg
fun :: Sel Char -> Char
fun sel = get sel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment