Created
October 15, 2019 19:15
-
-
Save mniip/1930d7a36f20d00a4d2d68f0e5495058 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type family KnownBools (bs :: [Bool]) :: Constraint where | |
KnownBools '[] = () | |
KnownBools (b ': bs) = (KnownBool b, KnownBools bs) | |
type family KnownBools (bs :: [Bool]) :: Constraint where | |
KnownBools '[] = () | |
KnownBools '[b1] = (KnownBool b1) | |
KnownBools '[b1, b2] = (KnownBool b1, KnownBool b2) | |
KnownBools '[b1, b2, b3] = (KnownBool b1, KnownBool b2, KnownBool b3) | |
KnownBools (b1 ': b2 ': b3 ': b4 ': bs) = (KnownBool b1, KnownBool b2, KnownBool b3, KnownBool b4, KnownBools bs) |
Simpler, but still divide and conquer:
type family Evens xs where
Evens (x : xs) = x : Odds xs
Evens '[] = '[]
type family Odds xs where
Odds (x : xs) = Evens xs
Odds '[] = '[]
type family KnownBools bs :: Constraint where
KnownBools '[] = ()
KnownBools '[b] = KnownBool b
KnownBools xs = (KnownBools (Evens xs), KnownBools (Odds xs))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How does divide and conquer compare?