Commit 295ac466 authored by Mart Lubbers's avatar Mart Lubbers

Merge branch '15-export-strictness-information-macros-for-one-line-operators' into 'master'

Resolve "export strictness information & macros for one-line operators"

Closes #15

See merge request !67
parents bf9a0a74 5fbf3aa6
Pipeline #8103 passed with stage
in 2 minutes and 12 seconds
......@@ -8,9 +8,9 @@ from Data.Monoid import class Monoid, class Semigroup
:: Const a b = Const a
:: WrappedMonad m a = WrapMonad (m a)
unwrapMonad :: (WrappedMonad m a) -> m a
unwrapMonad :: !(WrappedMonad m a) -> m a
getConst :: (Const a b) -> a
getConst :: !(Const a b) -> a
instance Applicative ((->) r)
instance Applicative Maybe
......@@ -32,11 +32,11 @@ instance Monoid (Const a b) | Monoid a
class Applicative f | Functor f where
pure :: a -> f a
(<*>) infixl 4 :: (f (a -> b)) (f a) -> f b
(<*>) infixl 4 :: !(f (a -> b)) (f a) -> f b
class Alternative f | Applicative f where
empty :: f a
(<|>) infixl 3 :: (f a) (f a) -> f a
(<|>) infixl 3 :: !(f a) (f a) -> f a
some :: (f a) -> f [a] | Alternative f
......@@ -52,7 +52,7 @@ many :: (f a) -> f [a] | Alternative f
* Be aware that the execution order has to be correct: the left hand side must
* be evaluated before the right hand side.
*/
class (*>) infixl 4 f :: (f a) (f b) -> f b | Applicative f
class (*>) infixl 4 f :: !(f a) (f b) -> f b | Applicative f
instance *> f
instance *> Maybe
......@@ -63,7 +63,7 @@ instance *> Maybe
* Be aware that the execution order has to be correct: the left hand side must
* be evaluated before the right hand side.
*/
class (<*) infixl 4 f :: (f a) (f b) -> f a | Applicative f
class (<*) infixl 4 f :: !(f a) (f b) -> f a | Applicative f
instance <* f
instance <* Maybe
......
......@@ -6,7 +6,7 @@ from Data.Monoid import class Monoid, class Semigroup
import qualified Data.Monoid as DM
from StdFunc import id, o, flip, const
getConst :: (Const a b) -> a
getConst :: !(Const a b) -> a
getConst (Const x) = x
instance Functor (Const m) where
......@@ -22,7 +22,7 @@ instance Applicative (Const m) | Monoid m where
pure _ = Const 'DM'.mempty
(<*>) (Const f) (Const v) = Const ('DM'.mappend f v)
unwrapMonad :: (WrappedMonad m a) -> m a
unwrapMonad :: !(WrappedMonad m a) -> m a
unwrapMonad (WrapMonad x) = x
instance Functor (WrappedMonad m) | Monad m where
......
......@@ -5,7 +5,19 @@ from Data.Functor import class Functor
from Data.Maybe import :: Maybe
class Monad m | Applicative m where
bind :: (m a) (a -> m b) -> m b
bind :: !(m a) (a -> m b) -> m b
(>>=) infixl 1 :: (m a) (a -> m b) -> m b
(>>=) ma a2mb :== bind ma a2mb
(`b`) infixl 1 :: (m a) (a -> m b) -> m b
(`b`) ma a2mb :== bind ma a2mb
(>>|) infixl 1 :: (m a) (m b) -> m b | Monad m
(>>|) ma mb :== ma >>= \_ -> mb
(=<<) infixr 1 :: (a -> m b) (m a) -> m b
(=<<) f x :== x >>= f
instance Monad ((->) r)
......@@ -15,27 +27,23 @@ instance Monad Maybe
class MonadPlus m | Monad m where
mzero :: m a
mplus :: (m a) (m a) -> m a
mplus :: !(m a) (m a) -> m a
instance MonadPlus []
instance MonadPlus Maybe
(>>=) infixl 1 :: (m a) (a -> m b) -> m b | Monad m
(`b`) infixl 1 :: (m a) (a -> m b) -> m b | Monad m
(>>|) infixl 1 :: (m a) (m b) -> m b | Monad m
(=<<) infixr 1 :: (a -> m b) (m a) -> m b | Monad m
sequence :: .[a b] -> a [b] | Monad a
sequence_ :: .[a b] -> a () | Monad a
mapM :: (.a -> b c) [.a] -> b [c] | Monad b
mapM_ :: (.a -> b c) [.a] -> b () | Monad b
sequence :: !.[a b] -> a [b] | Monad a
sequence_ :: !.[a b] -> a () | Monad a
mapM :: (.a -> b c) ![.a] -> b [c] | Monad b
mapM_ :: (.a -> b c) ![.a] -> b () | Monad b
forM :: u:([v:a] -> w:((v:a -> b c) -> b [c])) | Monad b, [w <= u,w <= v]
forM_ :: u:([v:a] -> w:((v:a -> b c) -> b ())) | Monad b, [w <= u,w <= v]
forever :: (a b) -> a c | Monad a
join :: (a (a b)) -> a b | Monad a
zipWithM :: (.a -> .(.b -> c d)) [.a] [.b] -> c [d] | Monad c
foldM :: (a -> .(b -> c a)) a [b] -> c a | Monad c
replicateM :: .Int (a b) -> a [b] | Monad a
zipWithM :: (.a -> .(.b -> c d)) ![.a] [.b] -> c [d] | Monad c
foldM :: (a -> .(b -> c a)) a ![b] -> c a | Monad c
replicateM :: !.Int (a b) -> a [b] | Monad a
(>=>) infixr 1 :: u:(.a -> b c) (c -> b d) -> v:(.a -> b d) | Monad b, [v <= u]
(<=<) infixr 1 :: u:((a -> b c) -> v:(w:(.d -> b a) -> x:(.d -> b c))) | Monad b, [v <= u,x <= w]
liftM :: (a -> b) (c a) -> c b | Monad c
......
......@@ -28,30 +28,18 @@ instance MonadPlus Maybe where
mplus Nothing ys = ys
mplus xs _ = xs
(>>=) infixl 1 :: (m a) (a -> m b) -> m b | Monad m
(>>=) ma a2mb = bind ma a2mb
(`b`) infixl 1 :: (m a) (a -> m b) -> m b | Monad m
(`b`) ma a2mb = bind ma a2mb
(>>|) infixl 1 :: (m a) (m b) -> m b | Monad m
(>>|) ma mb = ma >>= \_ -> mb
(=<<) infixr 1 :: (a -> m b) (m a) -> m b | Monad m
(=<<) f x = x >>= f
sequence :: .[a b] -> a [b] | Monad a
sequence :: !.[a b] -> a [b] | Monad a
sequence ms = foldr k (lift []) ms
where
k m m` = m >>= \x -> m` >>= \xs -> lift [x:xs]
sequence_ :: .[a b] -> a () | Monad a
sequence_ :: !.[a b] -> a () | Monad a
sequence_ ms = foldr (>>|) (lift ()) ms
mapM :: (.a -> b c) [.a] -> b [c] | Monad b
mapM :: (.a -> b c) ![.a] -> b [c] | Monad b
mapM f as = sequence (map f as)
mapM_ :: (.a -> b c) [.a] -> b () | Monad b
mapM_ :: (.a -> b c) ![.a] -> b () | Monad b
mapM_ f as = sequence_ (map f as)
forM :: u:([v:a] -> w:((v:a -> b c) -> b [c])) | Monad b, [w <= u,w <= v]
......@@ -66,14 +54,14 @@ forever a = let a` = a >>| a` in a`
join :: (a (a b)) -> a b | Monad a
join x = x >>= id
zipWithM :: (.a -> .(.b -> c d)) [.a] [.b] -> c [d] | Monad c
zipWithM :: (.a -> .(.b -> c d)) ![.a] [.b] -> c [d] | Monad c
zipWithM f xs ys = sequence (zipWith f xs ys)
foldM :: (a -> .(b -> c a)) a [b] -> c a | Monad c
foldM :: (a -> .(b -> c a)) a ![b] -> c a | Monad c
foldM _ a [] = lift a
foldM f a [x:xs] = f a x >>= \fax -> foldM f fax xs
replicateM :: .Int (a b) -> a [b] | Monad a
replicateM :: !.Int (a b) -> a [b] | Monad a
replicateM n x = sequence (replicate n x)
(>=>) infixr 1 :: u:(.a -> b c) (c -> b d) -> v:(.a -> b d) | Monad b, [v <= u]
......
......@@ -20,7 +20,7 @@ from System.File import :: FileError
* @param The message for which to compute the digest
* @return The ascii hex representation of the message digest
*/
sha1 :: String -> String
sha1 :: !String -> String
/**
* Compute the SHA1 digest of a string
......@@ -28,7 +28,7 @@ sha1 :: String -> String
* @param The message for which to compute the digest
* @return The raw 160 bit digest
*/
sha1StringDigest :: String -> SHA1Digest
sha1StringDigest :: !String -> SHA1Digest
/**
* Compute the SHA1 digest of the contents of a file
......@@ -38,7 +38,7 @@ sha1StringDigest :: String -> SHA1Digest
* @return The raw 160 bit digest
* @return The environment
*/
sha1FileDigest :: FilePath *env -> (!MaybeError FileError SHA1Digest,!*env) | FileSystem env
sha1FileDigest :: !FilePath !*env -> (!MaybeError FileError SHA1Digest, !*env) | FileSystem env
/**
* Print a SHA1 digest as ascii hexadecimal form
......
......@@ -12,10 +12,10 @@ import Data.Tuple, Text, System.FilePath, System.File, Data.Error, Data.Functor
*/
:: SHA1Digest = SHA1Digest {#Char} // 160 bit (20byte) message digest
sha1 :: String -> String
sha1 :: !String -> String
sha1 msg = toString (sha1StringDigest msg)
sha1StringDigest :: String -> SHA1Digest
sha1StringDigest :: !String -> SHA1Digest
sha1StringDigest msg = SHA1Digest (toBytes (foldl processChunk initState (chunk (pad msg))))
where
//Pre-processing:
......@@ -91,7 +91,7 @@ where
//The file digest is computed very dumb. Reading the full file and then hashing
//This can be optimized in the future because the digest can also be computed streaming
sha1FileDigest :: FilePath *env -> (!MaybeError FileError SHA1Digest,!*env) | FileSystem env
sha1FileDigest :: !FilePath !*env -> (!MaybeError FileError SHA1Digest,!*env) | FileSystem env
sha1FileDigest path env
= appFst (fmap sha1StringDigest) (readFile path env)
......
......@@ -12,14 +12,14 @@ from Data.IntMap.Strict import :: IntMap
newStack :: !Int -> CircularStack a
push :: a (CircularStack a) -> CircularStack a
push :: !a !(CircularStack a) -> CircularStack a
pop :: (CircularStack a) -> (Maybe a, CircularStack a)
pop :: !(CircularStack a) -> (!Maybe a, !CircularStack a)
peek :: (CircularStack a) -> Maybe a
peek :: !(CircularStack a) -> Maybe a
emptyStack :: (CircularStack a) -> Bool
emptyStack :: !(CircularStack a) -> Bool
fromList :: [a] -> CircularStack a
fromList :: ![a] -> CircularStack a
toList :: (CircularStack a) -> [a]
toList :: !(CircularStack a) -> [a]
......@@ -14,7 +14,7 @@ newStack n = { CircularStack
, stackData = 'DIS'.newMap
}
push :: a (CircularStack a) -> CircularStack a
push :: !a !(CircularStack a) -> CircularStack a
push x stack
= { stack
& stackData = 'DIS'.put stack.nextIdx x stack.stackData
......@@ -24,7 +24,7 @@ push x stack
, nextIdx = (stack.nextIdx + 1) modulo stack.maxSize
}
pop :: (CircularStack a) -> (Maybe a, CircularStack a)
pop :: !(CircularStack a) -> (!Maybe a, !CircularStack a)
pop stack
| emptyStack stack = (Nothing, stack)
| otherwise
......@@ -34,20 +34,20 @@ pop stack
& nextIdx = topIdx
, actualSize = stack.actualSize - 1})
peek :: (CircularStack a) -> Maybe a
peek :: !(CircularStack a) -> Maybe a
peek stack
| emptyStack stack = Nothing
| otherwise = 'DIS'.get (topElemIdx stack) stack.stackData
topElemIdx :: (CircularStack a) -> Int
topElemIdx :: !(CircularStack a) -> Int
topElemIdx stack
| stack.nextIdx == 0 = stack.maxSize - 1
| otherwise = stack.nextIdx - 1
emptyStack :: (CircularStack a) -> Bool
emptyStack :: !(CircularStack a) -> Bool
emptyStack stack = stack.actualSize == 0
toList :: (CircularStack a) -> [a]
toList :: !(CircularStack a) -> [a]
toList stack
| emptyStack stack = []
| otherwise
......@@ -56,7 +56,7 @@ toList stack
Just x -> [x : toList stack]
_ -> toList stack
fromList :: [a] -> CircularStack a
fromList :: ![a] -> CircularStack a
fromList xs = foldr push (newStack (length xs)) xs
(modulo) infixr 4 :: !Int !Int -> Int
......
......@@ -22,4 +22,4 @@ instance <* (Either e)
instance Monad (Either e)
either :: (.a -> .c) (.b -> .c) (Either .a .b) -> .c
either :: (.a -> .c) (.b -> .c) !(Either .a .b) -> .c
......@@ -28,6 +28,6 @@ instance Monad (Either e) where
bind (Left l) _ = Left l
bind (Right r) k = k r
either :: (.a -> .c) (.b -> .c) (Either .a .b) -> .c
either :: (.a -> .c) (.b -> .c) !(Either .a .b) -> .c
either f _ (Left x) = f x
either _ g (Right y) = g y
......@@ -50,7 +50,7 @@ mb2error :: !e !(Maybe a) -> MaybeError e a
/**
* Returns st on Error, state continuation on OK
*/
okSt :: *st (.a *st -> *st) (MaybeError .e .a) -> *st
okSt :: *st (.a *st -> *st) !(MaybeError .e .a) -> *st
/**
* Converts a MaybeError value into a Maybe value.
......
......@@ -42,7 +42,7 @@ liftError (Ok _) = abort "Data.Error.liftError: argument is Ok"
mb2error :: !e !(Maybe a) -> MaybeError e a
mb2error error mbV = maybe (Error error) Ok mbV
okSt :: *st (.a *st -> *st) (MaybeError .e .a) -> *st
okSt :: *st (.a *st -> *st) !(MaybeError .e .a) -> *st
okSt st f (Error _) = st
okSt st f (Ok x) = f x st
......
......@@ -39,43 +39,43 @@ from StdFunc import flip
//
class Foldable t where
// Combine the elements of a structure using a monoid.
fold :: (t m) -> m | Monoid m
fold :: !(t m) -> m | Monoid m
// Map each element of the structure to a monoid,
// and combine the results.
foldMap :: (a -> m) (t a) -> m | Monoid m
foldMap :: (a -> m) !(t a) -> m | Monoid m
// Right-associative fold of a structure.
//
// @'foldr' f z = 'Prelude.foldr' f z . 'toList'@
foldr :: (a b -> b) b (t a) -> b
foldr :: (a b -> b) b !(t a) -> b
// Right-associative fold of a structure,
// but with strict application of the operator.
foldr` :: (a b -> b) b (t a) -> b
foldr` :: (a b -> b) b !(t a) -> b
// Left-associative fold of a structure.
//
// @'foldl' f z = 'Prelude.foldl' f z . 'toList'@
foldl :: (b a -> b) b (t a) -> b
foldl :: (b a -> b) b !(t a) -> b
// Left-associative fold of a structure.
// but with strict application of the operator.
//
// @'foldl' f z = 'List.foldl'' f z . 'toList'@
foldl` :: (b a -> b) b (t a) -> b
foldl` :: (b a -> b) b !(t a) -> b
// A variant of 'foldr' that has no base case,
// and thus may only be applied to non-empty structures.
//
// @'foldr1' f = 'Prelude.foldr1' f . 'toList'@
foldr1 :: (a a -> a) (t a) -> a
foldr1 :: (a a -> a) !(t a) -> a
// A variant of 'foldl' that has no base case,
// and thus may only be applied to non-empty structures.
//
// @'foldl1' f = 'Prelude.foldl1' f . 'toList'@
foldl1 :: (a a -> a) (t a) -> a
foldl1 :: (a a -> a) !(t a) -> a
instance Foldable Maybe
instance Foldable []
......
......@@ -13,46 +13,6 @@ import StdClass
from StdOverloaded import class < (..)
from StdBool import not
class Foldable t where
// Combine the elements of a structure using a monoid.
fold :: (t m) -> m | Monoid m
// Map each element of the structure to a monoid,
// and combine the results.
foldMap :: (a -> m) (t a) -> m | Monoid m
// Right-associative fold of a structure.
//
// @'foldr' f z = 'Prelude.foldr' f z . 'toList'@
foldr :: (a b -> b) b (t a) -> b
// Right-associative fold of a structure,
// but with strict application of the operator.
foldr` :: (a b -> b) b (t a) -> b
// Left-associative fold of a structure.
//
// @'foldl' f z = 'Prelude.foldl' f z . 'toList'@
foldl :: (b a -> b) b (t a) -> b
// Left-associative fold of a structure.
// but with strict application of the operator.
//
// @'foldl' f z = 'List.foldl'' f z . 'toList'@
foldl` :: (b a -> b) b (t a) -> b
// A variant of 'foldr' that has no base case,
// and thus may only be applied to non-empty structures.
//
// @'foldr1' f = 'Prelude.foldr1' f . 'toList'@
foldr1 :: (a a -> a) (t a) -> a
// A variant of 'foldl' that has no base case,
// and thus may only be applied to non-empty structures.
//
// @'foldl1' f = 'Prelude.foldl1' f . 'toList'@
foldl1 :: (a a -> a) (t a) -> a
instance Foldable Maybe where
fold x = foldMap id x
foldMap f x = foldr (mappend o f) mempty x
......
......@@ -7,7 +7,7 @@ app f :== f
seqSt :: !(a .st -> .st) ![a] !.st -> .st
mapSt :: !(a .st -> (!b,!.st)) ![a] !.st -> (![b],!.st)
fix :: (a -> a) -> a
fix :: !(a -> a) -> a
on :: (b b -> c) (a -> b) -> (a a -> c)
//Evaluate the expression
......
......@@ -11,7 +11,7 @@ mapSt f [x:xs] st
#! (ys, st) = mapSt f xs st
= ([y:ys], st)
fix :: (a -> a) -> a
fix :: !(a -> a) -> a
fix f = let x = f x in x
on :: (b b -> c) (a -> b) -> (a a -> c)
......
definition module Data.Functor
from System.IO import :: IO
from StdFunc import const
class Functor f where
fmap :: (a -> b) (f a) -> f b
fmap :: (a -> b) !(f a) -> f b
instance Functor ((->) r)
instance Functor ((,) a)
(<$>) infixl 4 :: (a -> b) !(f a) -> f b
(<$>) f fa :== fmap f fa
(<$) infixl 4 :: a !(f b) -> f a
(<$) x fa :== fmap (const x) fa
(<$>) infixl 4 :: (a -> b) (f a) -> f b | Functor f
($>) infixl 4 :: !(f b) a -> f a
($>) fa x :== x <$ fa
(<$) infixl 4 :: a (f b) -> f a | Functor f
void :: !(f a) -> f ()
void x :== () <$ x
($>) infixl 4 :: (f b) a -> f a | Functor f
instance Functor ((->) r)
instance Functor ((,) a)
void :: (f a) -> f () | Functor f
implementation module Data.Functor
from StdFunc import o, const
from StdFunc import o
import Control.Applicative
import Control.Monad
instance Functor ((->) r) where
fmap f g = \x -> (f o g) x
......@@ -10,14 +9,3 @@ instance Functor ((->) r) where
instance Functor ((,) a) where
fmap f (x, y) = (x, f y)
(<$>) infixl 4 :: (a -> b) (f a) -> (f b) | Functor f
(<$>) f fa = fmap f fa
(<$) infixl 4 :: a (f b) -> f a | Functor f
(<$) x fa = fmap (const x) fa
($>) infixl 4 :: (f b) a -> f a | Functor f
($>) fa x = x <$ fa
void :: (f a) -> f () | Functor f
void x = () <$ x
......@@ -18,7 +18,7 @@ from Data.Maybe import :: Maybe
instance == (IntMap a) | == a
equal :: (IntMap a) (IntMap a) -> Bool | == a
equal :: !(IntMap a) !(IntMap a) -> Bool | == a
bin :: !Prefix !Mask !(IntMap a) !(IntMap a) -> IntMap a
......@@ -26,13 +26,13 @@ nomatch :: !Int !Prefix !Mask -> Bool
empty :: IntMap a
foldrWithKey :: (Int a b -> b) b (IntMap a) -> b
foldrWithKey :: (Int a b -> b) b !(IntMap a) -> b
fromDistinctAscList :: ![(!Int, !a)] -> IntMap a
union :: (IntMap a) (IntMap a) -> IntMap a
union :: !(IntMap a) !(IntMap a) -> IntMap a
unions :: [IntMap a] -> IntMap a
unions :: ![IntMap a] -> IntMap a
mask :: !Int !Mask -> Prefix
......@@ -45,14 +45,14 @@ branchMask :: !Prefix !Prefix -> Mask
//
// > minViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((3,"b"), singleton 5 "a")
// > minViewWithKey empty == Nothing
minViewWithKey :: (IntMap a) -> Maybe ((Int, a), IntMap a)
minViewWithKey :: !(IntMap a) -> Maybe ((Int, a), IntMap a)
// | /O(min(n,W))/. Retrieves the maximal (key,value) pair of the map, and
// the map stripped of that element, or 'Nothing' if passed an empty map.
//
// > maxViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((5,"a"), singleton 3 "b")
// > maxViewWithKey empty == Nothing
maxViewWithKey :: (IntMap a) -> Maybe ((Int, a), IntMap a)
maxViewWithKey :: !(IntMap a) -> Maybe ((Int, a), IntMap a)
// | /O(min(n,W))/. Lookup the value at a key in the map. See also 'Data.Map.lookup'.
lookup :: !Int (IntMap a) -> Maybe a
lookup :: !Int !(IntMap a) -> Maybe a
......@@ -141,7 +141,7 @@ notMember :: Int (IntMap a) -> Bool
notMember k m = not (member k m)
// | /O(min(n,W))/. Lookup the value at a key in the map. See also 'Data.Map.lookup'.
lookup :: !Int (IntMap a) -> Maybe a
lookup :: !Int !(IntMap a) -> Maybe a
lookup k (Bin p m l r)
| nomatch k p m = Nothing
| zero k m = lookup k l
......@@ -506,7 +506,7 @@ alter f k t =
// > == fromList [(3, "b"), (5, "a"), (7, "C")]
// > unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])]
// > == fromList [(3, "B3"), (5, "A3"), (7, "C")]
unions :: [IntMap a] -> IntMap a
unions :: ![IntMap a] -> IntMap a
unions xs = foldlStrict union empty xs
// | The union of a list of maps, with a combining operation.
......@@ -521,7 +521,7 @@ unionsWith f ts = foldlStrict (unionWith f) empty ts
// i.e. (@'union' == 'unionWith' 'const'@).
//
// > union (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "a"), (7, "C")]
union :: (IntMap a) (IntMap a) -> IntMap a
union :: !(IntMap a) !(IntMap a) -> IntMap a
union m1 m2 = mergeWithKey` Bin const id id m1 m2
// | /O(n+m)/. The union with a combining function.
......@@ -721,7 +721,7 @@ updateMaxWithKey f t =
//
// > maxViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((5,"a"), singleton 3 "b")
// > maxViewWithKey empty == Nothing
maxViewWithKey :: (IntMap a) -> Maybe ((Int, a), IntMap a)
maxViewWithKey :: !(IntMap a) -> Maybe ((Int, a), IntMap a)
maxViewWithKey t =