Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use (,) instead of a custom Pair type.

  • Loading branch information...
commit 1febd0976c94d99e9f7539d54a04aea89a73f26a 1 parent 0b9754b
@23Skidoo authored
View
2  src/CFG/Helpers/CNF.hs
@@ -25,4 +25,4 @@ compileGrammar (CNFGrammar rules start e) =
CNFTerminalRule (lookupName name) symbol
compileRule (CNFNonTerminalRule name prods) =
CNFNonTerminalRule (lookupName name)
- [Pair (lookupName a) (lookupName b) | Pair a b <- prods]
+ [((lookupName a), (lookupName b)) | (a, b) <- prods]
View
2  src/CFG/Parse.hs
@@ -35,7 +35,7 @@ cykAlgorithm grammar input' = if n == 0
forM_ [1..(i-1)] $ \k ->
forM_ (filter isNonTerminalRule rules) $ \rule -> do
let a = ruleNumber rule
- forM_ (nonTerminalRuleProductions rule) $ \(Pair b c) -> do
+ forM_ (nonTerminalRuleProductions rule) $ \(b, c) -> do
e0 <- readArray marr (j,k,b)
e1 <- readArray marr (j+k,i-k,c)
when (e0 && e1) $
View
2  src/CFG/Read.hs
@@ -116,7 +116,7 @@ cnfRuleP = do
case mTerm of
Just t -> return $ CNFTerminalRule name t
Nothing -> do
- rhs <- pure Pair <*> ruleNameP <*> ruleNameP
+ rhs <- pure (,) <*> ruleNameP <*> ruleNameP
return $ CNFNonTerminalRule name [rhs]
-- | A rule name: an upper-case letter followed by zero or more digits.
View
14 src/CFG/Types.hs
@@ -9,7 +9,7 @@ module CFG.Types (
,NamedCFGRule, NumberedCFGRule
,NamedCFGrammar, CompiledCFGrammar
- ,Pair(..), CNFRule(..), CNFGrammar(..)
+ ,CNFRule(..), CNFGrammar(..)
,NamedCNFRule, NumberedCNFRule
,NamedCNFGrammar, CompiledCNFGrammar
@@ -44,10 +44,8 @@ type NamedCFGrammar = CFGrammar RuleName
type CompiledCFGrammar = CFGrammar RuleNumber
-- A context-free grammar in CNF form.
-data Pair a = Pair !a !a
- deriving (Eq, Show)
data CNFRule a = CNFTerminalRule !a !Symbol
- | CNFNonTerminalRule !a ![Pair a]
+ | CNFNonTerminalRule !a ![(a,a)]
deriving (Eq, Show)
type NamedCNFRule = CNFRule RuleName
@@ -64,8 +62,8 @@ type CompiledCNFGrammar = CNFGrammar RuleNumber
-- Basic helpers.
-- | Helpers for rules.
-class Rule r where
- type NonTermProduction r :: * -> *
+class Rule (r :: * -> *) where
+ type NonTermProduction r a :: *
ruleName :: r a -> a
ruleName = ruleNumber
@@ -81,7 +79,7 @@ class Rule r where
mkNonTerminal :: a -> [NonTermProduction r a] -> r a
instance Rule CFGRule where
- type NonTermProduction CFGRule = []
+ type NonTermProduction CFGRule a = [a]
ruleName (CFGTerminalRule name _) = name
ruleName (CFGNonTerminalRule name _) = name
@@ -101,7 +99,7 @@ instance Rule CFGRule where
mkNonTerminal name prods = CFGNonTerminalRule name prods
instance Rule CNFRule where
- type NonTermProduction CNFRule = Pair
+ type NonTermProduction CNFRule a = (a,a)
ruleName (CNFTerminalRule name _) = name
ruleName (CNFNonTerminalRule name _) = name
Please sign in to comment.
Something went wrong with that request. Please try again.