Last active
October 10, 2017 20:15
-
-
Save kcsongor/cad42ed896f6740b4d9d7e2dab040300 to your computer and use it in GitHub Desktop.
Toying with type-level regular expressions
This file contains hidden or 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
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE ExistentialQuantification #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module Regex where | |
data RE | |
= forall (a :: *). Term a | |
| Null | |
| RE :| RE | |
type family Or (a :: Bool) (b :: Bool) :: Bool where | |
Or 'True b = 'True | |
Or 'False b = b | |
type family Match a (b :: RE) where | |
Match a ('Term a) = 'True | |
Match a (m1 ':| m2) = Match a m1 `Or` Match a m2 | |
Match a b = 'False | |
x :: Match a ('Term Char ':| 'Term Int) ~ 'True => a -> a -> a | |
x = const |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment