Skip to content

Instantly share code, notes, and snippets.

@mstksg
Created March 28, 2018 23:46
Show Gist options
  • Save mstksg/16b3dce301d0c3794dc37f146ae6217b to your computer and use it in GitHub Desktop.
Save mstksg/16b3dce301d0c3794dc37f146ae6217b to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeInType #-}
data These a b = Neither
| This a
| That b
| These a b
type family ToThese (a :: Maybe k) (b :: Maybe j) = (c :: These k j) where
ToThese 'Nothing 'Nothing = 'Neither
ToThese ('Just a) 'Nothing = 'This a
ToThese 'Nothing ('Just b) = 'That b
ToThese ('Just a) ('Just b) = 'These a b
type family ToThese' (ab :: (Maybe k, Maybe j)) = (c :: These k j) | c -> ab where
ToThese' '( 'Nothing, 'Nothing) = 'Neither
ToThese' '( 'Just a , 'Nothing) = 'This a
ToThese' '( 'Nothing, 'Just b ) = 'That b
ToThese' '( 'Just a , 'Just b ) = 'These a b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment