From: Francis Russell Date: Sat, 15 Sep 2012 16:56:08 +0000 (+0100) Subject: Replace folds with strict versions. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=5f42f9d069db07d7d16a3f1b276631bdd63901eb;p=francis%2Fofc.git Replace folds with strict versions. --- diff --git a/src/ParsedOFL.hs b/src/ParsedOFL.hs index 27bbd2c..95ee451 100644 --- a/src/ParsedOFL.hs +++ b/src/ParsedOFL.hs @@ -1,5 +1,6 @@ module ParsedOFL where import Data.Map as Map (Map, lookup, insertWithKey, empty) +import Data.List (foldl') -- The top-level types data BaseType = RealType | FunctionType | IntegerType deriving (Eq, Enum, Bounded) @@ -151,7 +152,7 @@ validateExpression :: OFL -> Expression -> ValidationResult validateExpression ofl (IndexedIdentifier name indices) = do valueExists ofl name - foldl (>>) validationSuccess $ map (indexExists ofl) indices + foldl' (>>) validationSuccess $ map (indexExists ofl) indices let indexTypes = map (getIndexType ofl) indices in case indexTypes == (getIndices ofl name) of True -> validationSuccess diff --git a/src/Parsing.hs b/src/Parsing.hs index 0fc0914..9cbc284 100644 --- a/src/Parsing.hs +++ b/src/Parsing.hs @@ -1,5 +1,6 @@ module Parsing where import ParsedOFL +import Data.List (foldl1') import Text.Parsec import Text.Parsec.Expr import Text.Parsec.Token @@ -41,8 +42,8 @@ oflOperatorTable = [[Infix (do _ <- lSymbol "^"; return (\x y -> Power x y)) As ,Infix (do _ <- lSymbol "-"; return (\x y -> Sub x y)) AssocLeft] ] -parseType = foldl1 (<|>) [do lReserved $ show t; return t | t <- [minBound::BaseType ..]] -parseIndex = foldl1 (<|>) [do lReserved $ show t; return t | t <- [minBound::IndexType ..]] +parseType = foldl1' (<|>) [do lReserved $ show t; return t | t <- [minBound::BaseType ..]] +parseIndex = foldl1' (<|>) [do lReserved $ show t; return t | t <- [minBound::IndexType ..]] parseDeclaration :: Parsec String OFL () parseDeclaration = parseValueDeclaration <|> parseIndexDeclaration @@ -52,14 +53,14 @@ parseValueDeclaration = do valueType <- parseType indices <- option [] (lBrackets $ lCommaSep parseIndex) names <- lCommaSep1 parseIdentifier - foldl1 (>>) [modifyState(\x -> addValueDeclaration x name valueType indices) | name <- names] + foldl1' (>>) [modifyState(\x -> addValueDeclaration x name valueType indices) | name <- names] "value declaration" parseIndexDeclaration :: Parsec String OFL () parseIndexDeclaration = do indexType <- parseIndex names <- lCommaSep1 parseIdentifier - foldl1 (>>) [modifyState(\x -> addIndexDeclaration x name indexType) | name <- names] + foldl1' (>>) [modifyState(\x -> addIndexDeclaration x name indexType) | name <- names] "index declaration" parseIdentifier = lIdentifier "identifier"