Replace star with Type

This commit is contained in:
rnhmjoj 2016-11-27 20:17:27 +01:00
parent b9f249a9ff
commit 9d3ec1d2ad
No known key found for this signature in database
GPG Key ID: 362BB82B7E496B7C

View File

@ -18,6 +18,7 @@
module Data.Vec where
import Relation.Equality (gcastWith)
import Data.Kind (Type)
import Data.Nat
import Data.Bool
import Data.Char (Char)
@ -31,7 +32,7 @@ import qualified Data.TypeClass as T
infixr 5 :-
-- | The 'Vec' datatype
data Vec where
data Vec Type Type where
Nil Vec a Z -- ^ empty 'Vec', length 0
(:-) a Vec a n Vec a (S n) -- ^ "cons" operator
@ -197,27 +198,27 @@ permutations xs@(_:-_) = concatMap (\(y,ys) → map (y:-) (permutations ys)) (se
-- and a 'Vec' reduces the vector to a single value obtained
-- by sequentially applying the operation from the left to the right.
foldl (a b a) a Vec b n a
foldl _ x Nil = x
foldl _ x Nil = x
foldl () x (y :- ys) = foldl () (x y) ys
-- | Same as "fold" but reduces the vector in the opposite
-- direction: from the right to the left.
foldr (a b b) b Vec a n b
foldr _ x Nil = x
foldr _ x Nil = x
foldr () x (y:-ys) = y (foldr () x ys)
-- | Variant of 'foldl' which requires no starting value but
-- applies only on nonempty 'Vec'
foldl (a a a) Vec a (S n) a
foldl _ (x :- Nil) = x
foldl _ (x :- Nil) = x
foldl () (x :- y :- ys) = foldl () (x y :- ys)
-- | As for 'foldl', a variant of 'foldr' with no starting point
foldr (a a a) Vec a (S n) a
foldr _ (x :- Nil) = x
foldr _ (x :- Nil) = x
foldr () (x :- y :- ys) = x (foldr () (y :- ys))