Skip to content

Commit

Permalink
remove the dependency on GADTs
Browse files Browse the repository at this point in the history
darcs-hash:20060825164425-f399b-3c84300285d9f87b4ed1375a802ebedf0c141a6f
  • Loading branch information
robdockins committed Aug 25, 2006
1 parent 2601c3d commit 75d837d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Shellac.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ Build-Depends:
Extensions:
MultiParamTypeClasses
FunctionalDependencies
ExistentialQuantification
ExistentialQuantification
CPP
-- GADT
-- STM
Exposed-modules:
System.Console.Shell
Expand Down
30 changes: 13 additions & 17 deletions src/System/Console/Shell/Regex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- They are used to parse the arguments to shell commands and to give
- information about the type of the argument at a position in the
- string to allow positional word completion. The REs are directly
- intertreted in the list monad, so effeciency isn't so great, but
- interpreted in the list monad, so effeciency isn't so great, but
- for most shell command lines that won't matter too much.
-}

Expand All @@ -19,25 +19,21 @@ import Control.Monad ( MonadPlus(..) )


{- The type of regular expressions. Regular expressions evaluation
calculates a result value as well as recognizing strings in a language,
so we use a GADT which follows the structure of the evaluation.
calculates a result value as well as recognizing strings in a language.
The Regex data type was originally coded as a GADT. However, only exestentials
are required, so it is reformulated here using existential quantification.
-}

-- hide GADTs from haddock
#ifndef __HADDOCK__
data Regex a x
= Empty
| Epsilon x
| Label String (Regex a x)
| Terminal (a -> Bool) (a -> x) String
| External ([a] -> [(x,[a])]) String
| forall p q. Concat (p -> q -> x) (Regex a p) (Regex a q)
| forall p q. Alt (Either p q -> x) (Regex a p) (Regex a q)
| forall p . Star ([p] -> x) (Regex a p)

data Regex a x where
Empty :: Regex a x
Epsilon :: x -> Regex a x
Label :: String -> Regex a x -> Regex a x
Terminal :: (a -> Bool) -> (a -> x) -> String -> Regex a x
External :: ([a] -> [(x,[a])]) -> String -> Regex a x

Concat :: (p -> q -> x) -> Regex a p -> Regex a q -> Regex a x
Alt :: (Either p q -> x) -> Regex a p -> Regex a q -> Regex a x
Star :: ([p] -> x) -> Regex a p -> Regex a x

#endif

{- Auxiliary type used to help remove unnecessary parenthesis when printing REs -}
data RegexContext
Expand Down

0 comments on commit 75d837d

Please sign in to comment.