Skip to content

Commit 08c9fc2

Browse files
committed
Test fixes
1 parent 0d48984 commit 08c9fc2

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

clash-prelude/src/Clash/Sized/Vector.hs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,24 +259,35 @@ instance NFData a => NFData (Vec n a) where
259259
--
260260
-- Can be used as a pattern:
261261
--
262-
-- >>> let f (x :> y :> _) = x + y
263-
-- >>> :t f
264-
-- f :: Num a => Vec ((n + 1) + 1) a -> a
262+
-- >>> :{
263+
-- f :: Num a => Vec (n + 2) a -> a
264+
-- f (x :> y :> _) = x + y
265+
-- :}
266+
--
265267
-- >>> f (3:>4:>5:>6:>7:>Nil)
266268
-- 7
267269
--
268270
-- Also in conjunctions with (':<'):
269271
--
270-
-- >>> let g (a :> b :> (_ :< y :< x)) = a + b + x + y
271-
-- >>> :t g
272-
-- g :: Num a => Vec ((((n + 1) + 1) + 1) + 1) a -> a
272+
-- >>> :{
273+
-- g :: Num a => Vec (n + 4) a -> a
274+
-- g (a :> b :> (_ :< y :< x)) = a + b + x + y
275+
-- :}
276+
--
273277
-- >>> g (1:>2:>3:>4:>5:>Nil)
274278
-- 12
279+
#if MIN_VERSION_base(4,15,0)
275280
pattern (:>) ::
276281
forall {n} a. () =>
277282
forall m. n ~ m + 1 =>
278283
a -> Vec m a -> Vec n a
279284
pattern (:>) x xs = Cons x xs
285+
#else
286+
pattern (:>) :: a -> Vec n a -> Vec (n + 1) a
287+
pattern (:>) x xs <- ((\ys -> (head ys,tail ys)) -> (x,xs))
288+
where
289+
(:>) x xs = Cons x xs
290+
#endif
280291

281292
infixr CONS_PREC :>
282293

@@ -676,9 +687,11 @@ infixl 5 :<
676687
--
677688
-- Also in conjunctions with (':>'):
678689
--
679-
-- >>> let g (a :> b :> (_ :< y :< x)) = a + b + x + y
680-
-- >>> :t g
681-
-- g :: Num a => Vec ((((n + 1) + 1) + 1) + 1) a -> a
690+
-- >>> :{
691+
-- g :: Num a => Vec (n + 4) a -> a
692+
-- g (a :> b :> (_ :< y :< x)) = a + b + x + y
693+
-- :}
694+
--
682695
-- >>> g (1:>2:>3:>4:>5:>Nil)
683696
-- 12
684697
pattern (:<) :: Vec n a -> a -> Vec (n+1) a
@@ -2385,7 +2398,7 @@ lazyV = lazyV' (repeat ())
23852398
-- While the type of (':>') is:
23862399
--
23872400
-- >>> :t (:>)
2388-
-- (:>) :: a -> Vec n a -> Vec (n + 1) a
2401+
-- (:>) :: (n ~ (m + 1)) => a -> Vec m a -> Vec n a
23892402
--
23902403
-- We thus need a @fold@ function that can handle the growing vector type:
23912404
-- 'dfold'. Compared to 'foldr', 'dfold' takes an extra parameter, called the

clash-prelude/src/Clash/Sized/Vector/ToTuple.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ class VecToTuple a where
5151
-- The following would produce a warning even though we can be sure
5252
-- no other pattern can ever apply:
5353
--
54-
-- >>> (a :> b :> c :> Nil) = myVec
54+
-- >>> :{
55+
-- a, b, c :: Int
56+
-- (a :> b :> c :> Nil) = myVec
57+
-- :}
5558
--
5659
-- 'vecToTuple' can be used to work around the warning:
5760
--

tests/shouldwork/Basic/T1340.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,14 @@ catLayout (BitLayout aBitCount aInFn aOutFn) (BitLayout bBitCount bInFn bOutFn)
7272
in BitLayout SNat inFn outFn
7373

7474
vecLayout
75-
:: forall n n' t
76-
. ( n' ~ (n - 1)
77-
, 1 <= n
78-
, KnownNat n
79-
, KnownNat n' )
75+
:: (1 <= n, KnownNat n)
8076
=> Vec n (BitLayout t)
8177
-> BitLayout (Vec n t)
8278
vecLayout (BitLayout{..} :> others) = let
8379
headLayout = BitLayout SNat (headSigFn >>> inFn) (outFn >>> singletonSigFn)
8480
in case others of
85-
Nil -> headLayout
86-
_ -> headLayout `catLayout` vecLayout @n' others
81+
Nil -> headLayout
82+
Cons _ _ -> headLayout `catLayout` vecLayout others
8783

8884
layout :: BitLayout (Vec Lanes Bit)
8985
layout = mkPos (0 :: Index (Lanes + 1))

tests/shouldwork/Basic/T1354B.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,14 @@ catLayout (BitLayout aBitCount aInFn aOutFn) (BitLayout bBitCount bInFn bOutFn)
7676
in BitLayout SNat inFn outFn
7777

7878
vecLayout
79-
:: forall n n' t
80-
. ( n' ~ (n - 1)
81-
, 1 <= n
82-
, KnownNat n
83-
, KnownNat n' )
79+
:: (1 <= n, KnownNat n)
8480
=> Vec n (BitLayout t)
8581
-> BitLayout (Vec n t)
8682
vecLayout (BitLayout{..} :> others) = let
8783
headLayout = BitLayout SNat (headSigFn >>> inFn) (outFn >>> singletonSigFn)
8884
in case others of
89-
Nil -> headLayout
90-
_ -> headLayout `catLayout` vecLayout @n' others
85+
Nil -> headLayout
86+
Cons _ _ -> headLayout `catLayout` vecLayout others
9187

9288
layout :: BitLayout (Vec Lanes Bit)
9389
layout = mkPos (0 :: Index (Lanes + 1))

0 commit comments

Comments
 (0)