Commit aa4329ae authored by Björn Peemöller 's avatar Björn Peemöller
Browse files

Removed some unused functions, added comments

parent 4dc0f607
{- |
Module : $Header$
Description : Construction and output of compiler messages
Copyright : (c) 2011 - 2016 Björn Peemöller
License : OtherLicense
Maintainer : bjp@informatik.uni-kiel.de
Stability : experimental
Portability : portable
This module defines several operations to construct and emit compiler
messages to the user.
-}
module Base.Messages
( -- * Output of user information
status, putErrLn, putErrsLn
MonadIO (..), status, putMsg, putErrLn, putErrsLn
-- * program abortion
, abortWith, abortWithMessage, abortWithMessages, warnOrAbort
, internalError, errorMessage, errorMessages
, abortWith, abortWithMessage, abortWithMessages, warnOrAbort, internalError
-- * creating messages
, Message, message, posMessage
, MonadIO (..)
) where
import Control.Monad (unless, when)
......@@ -20,6 +31,7 @@ import Curry.Base.Message ( Message, message, posMessage, ppWarning
import Curry.Base.Pretty (Doc, text)
import CompilerOpts (Options (..), WarnOpts (..), Verbosity (..))
-- |Print a status message, depending on the current verbosity
status :: MonadIO m => Options -> String -> m ()
status opts msg = unless (optVerbosity opts < VerbStatus) (putMsg msg)
......@@ -64,9 +76,3 @@ printMessages msgType msgs
-- |Raise an internal error
internalError :: String -> a
internalError msg = error $ "Internal error: " ++ msg
errorMessage :: Message -> a
errorMessage = error . show . ppError
errorMessages :: [Message] -> a
errorMessages = error . show . ppMessages ppError . sort
......@@ -35,6 +35,7 @@ instance Eq (Node a b) where
instance Ord (Node b a) where
n1 `compare` n2 = key n1 `compare` key n2
-- |Computation of strongly connected components
scc :: Eq b => (a -> [b]) -- ^entities defined by node
-> (a -> [b]) -- ^entities used by node
-> [a] -- ^list of nodes
......
......@@ -24,20 +24,27 @@ module Base.Subst
import qualified Data.Map as Map
data Subst a b = Subst Bool (Map.Map a b) deriving Show
-- |Data type for substitution
data Subst a b = Subst Bool (Map.Map a b)
deriving Show
-- |Identity substitution
idSubst :: Ord a => Subst a b
idSubst = Subst False Map.empty
-- |Convert a substitution to a list of replacements
substToList :: Ord v => Subst v e -> [(v, e)]
substToList (Subst _ sigma) = Map.toList sigma
-- |Create a substitution for a single replacement
singleSubst :: Ord v => v -> e -> Subst v e
singleSubst v e = bindSubst v e idSubst
-- |Extend a substitution with a single replacement
bindSubst :: Ord v => v -> e -> Subst v e -> Subst v e
bindSubst v e (Subst comp sigma) = Subst comp $ Map.insert v e sigma
-- |Remove a single replacement from a substitution
unbindSubst :: Ord v => v -> Subst v e -> Subst v e
unbindSubst v (Subst comp sigma) = Subst comp $ Map.delete v sigma
......@@ -80,6 +87,7 @@ unbindSubst v (Subst comp sigma) = Subst comp $ Map.delete v sigma
-- substVar (Subst comp sigma) v = maybe (var v) subst' (Map.lookup v sigma)
-- where subst' = if comp then subst (Subst comp sigma) else id
-- |Compose two substitutions
compose :: (Ord v, Show v ,Show e) => Subst v e -> Subst v e -> Subst v e
compose sigma sigma' =
composed (foldr (uncurry bindSubst) sigma' (substToList sigma))
......@@ -93,22 +101,26 @@ compose sigma sigma' =
-- module includes a class 'IntSubst' for substitution whose
-- domain are integer numbers.
-- |Apply a substitution to a variable
substVar' :: Ord v => (v -> e) -> (Subst v e -> e -> e)
-> Subst v e -> v -> e
substVar' var subst (Subst comp sigma) v =
maybe (var v) subst' (Map.lookup v sigma)
where subst' = if comp then subst (Subst comp sigma) else id
-- |Type class for terms where variables are represented as 'Int's
class IntSubst e where
-- |Construct a variable from an 'Int'
ivar :: Int -> e
-- |Apply a substitution to a term
isubst :: Subst Int e -> e -> e
-- |Apply a substitution to a term with variables represented as 'Int's
isubstVar :: IntSubst e => Subst Int e -> Int -> e
isubstVar = substVar' ivar isubst
-- The function 'restrictSubstTo' implements the restriction of a
-- |The function 'restrictSubstTo' implements the restriction of a
-- substitution to a given subset of its domain.
restrictSubstTo :: Ord v => [v] -> Subst v e -> Subst v e
restrictSubstTo vs (Subst comp sigma) =
foldr (uncurry bindSubst) (Subst comp Map.empty)
......
......@@ -15,19 +15,13 @@
-}
module Base.Utils
( thd3, (++!), foldr2, mapAccumM, findDouble, concatMapM, findMultiples
( (++!), foldr2, mapAccumM, findDouble, concatMapM, findMultiples
) where
import Data.List (partition)
infixr 5 ++!
-- The Prelude does not contain standard functions for triples.
-- We provide projection, (un-)currying, and mapping for triples here.
thd3 :: (a, b, c) -> c
thd3 (_, _, z) = z
-- The function (++!) is variant of the list concatenation operator (++)
-- that ignores the second argument if the first is a non-empty list.
-- When lists are used to encode non-determinism in Haskell,
......
......@@ -443,6 +443,7 @@ addFlag o opts = nub $ o : opts
removeFlag :: Eq a => a -> [a] -> [a]
removeFlag o opts = filter (/= o) opts
-- |Update the 'Options' record by the parsed and processed arguments
updateOpts :: Options -> [String] -> (Options, [String], [String])
updateOpts opts args = (opts', files, errs ++ errs2 ++ checkOpts opts files)
where
......
......@@ -16,7 +16,7 @@ import Data.List (intercalate)
import Curry.Base.Position (Position (..))
import Curry.Syntax (Token (..), Category (..), Attributes (..))
-- Show a list of 'Position' and 'Token' tuples.
-- |Show a list of 'Position' and 'Token' tuples.
-- The list is split into one tuple on each line to increase readability.
showTokenStream :: [(Position, Token)] -> String
showTokenStream [] = "[]\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment