Skip to content

Instantly share code, notes, and snippets.

@kcsongor
Last active October 10, 2017 20:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcsongor/cad42ed896f6740b4d9d7e2dab040300 to your computer and use it in GitHub Desktop.
Save kcsongor/cad42ed896f6740b4d9d7e2dab040300 to your computer and use it in GitHub Desktop.
Toying with type-level regular expressions
{-# 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