on master help sign in
Small fixes
321b1aeArmando Santos
app/Main.hs+6
@@ -29,8 +29,13 @@ secondChoice = fromF switch
29sumSS :: Natural 6 -> Natural 6 -> Natural 12
29sumSS :: Natural 6 -> Natural 6 -> Natural 12
30sumSS = coerceNat (+)
30sumSS = coerceNat (+)
31
31
32+mulSS :: Natural 6 -> Natural 6 -> Natural 36
33+mulSS = coerceNat (*)
34+
32sumSSM = fromF' (uncurry sumSS)
35sumSSM = fromF' (uncurry sumSS)
33
36
37+mulSSM3 = fromF' (mulSS (Nat 3))
38+
34die :: Dist (Natural 6) 6
39die :: Dist (Natural 6) 6
35die = uniform [nat @6 1 .. nat 6]
40die = uniform [nat @6 1 .. nat 6]
36
41
@@ -39,4 +44,5 @@ main = do
39 prettyPrint (p1 @Double @1 `comp` secondChoice `comp` firstChoice)
44 prettyPrint (p1 @Double @1 `comp` secondChoice `comp` firstChoice)
40 prettyPrint (sumSSM `comp` khatri die die)
45 prettyPrint (sumSSM `comp` khatri die die)
41 prettyPrint (bang `comp` sumSSM `comp` khatri die die)
46 prettyPrint (bang `comp` sumSSM `comp` khatri die die)
47+ prettyPrint firstPhase
42
48
src/Matrix/Nat.hs+7−8
@@ -430,14 +430,13 @@ tr (M m) = M (I.tr m)
430
430
431-- Selective 'select' operator
431-- Selective 'select' operator
432
432
433−select
433+select :: (Bounded a1, Bounded b, Enum a1, Enum b, Num e, Ord e,
434− :: (Num e, Bounded a1, Bounded b, Enum a1, Enum b, Ord e,
435− KnownNat (I.Count a2), KnownNat (I.Count (I.FromNat rows1)),
434+ KnownNat (I.Count a2), KnownNat (I.Count (I.FromNat rows1)),
436− I.FromLists e (I.FromNat rows1) a2,
435+ I.FromLists e (I.FromNat rows1) a2,
437− I.FromLists e (I.FromNat rows1) (I.FromNat rows1), Eq b,
436+ I.FromLists e (I.FromNat rows1) (I.FromNat rows1), Eq b,
438− I.FromNat cols1 ~ I.FromNat cols2,
437+ I.FromNat cols1 ~ I.FromNat cols2,
439− I.FromNat rows2 ~ Either a2 (I.FromNat rows1)) =>
438+ I.FromNat rows2 ~ Either a2 (I.FromNat rows1)) =>
440− Matrix e cols1 rows2 -> (a1 -> b) -> Matrix e cols2 rows1
439+ Matrix e cols1 rows2 -> (a1 -> b) -> Matrix e cols2 rows1
441select (M m) y = M (I.select m y)
440select (M m) y = M (I.select m y)
442
441
443-- McCarthy's Conditional
442-- McCarthy's Conditional
src/Matrix/Type.hs+12−19
@@ -226,8 +226,8 @@ instance {-# OVERLAPPING #-} FromLists e () () where
226 fromLists _ = error "Wrong dimensions"
226 fromLists _ = error "Wrong dimensions"
227
227
228instance (FromLists e cols ()) => FromLists e (Either () cols) () where
228instance (FromLists e cols ()) => FromLists e (Either () cols) () where
229− fromLists [(h : t)] = Junc (One h) (fromLists [t])
229+ fromLists [h : t] = Junc (One h) (fromLists [t])
230− fromLists _ = error "Wrong dimensions"
230+ fromLists _ = error "Wrong dimensions"
231
231
232instance (FromLists e () rows) => FromLists e () (Either () rows) where
232instance (FromLists e () rows) => FromLists e () (Either () rows) where
233 fromLists ([h] : t) = Split (One h) (fromLists t)
233 fromLists ([h] : t) = Split (One h) (fromLists t)
@@ -296,7 +296,7 @@ fromF f =
296 buildList l r = take r l : buildList (drop r l) r
296 buildList l r = take r l : buildList (drop r l) r
297
297
298fromF' ::
298fromF' ::
299− forall a b cols rows e.
299+ forall a b e.
300 ( Bounded a,
300 ( Bounded a,
301 Bounded b,
301 Bounded b,
302 Enum a,
302 Enum a,
@@ -492,7 +492,7 @@ infixl 4 ><
492abideJS :: Matrix e cols rows -> Matrix e cols rows
492abideJS :: Matrix e cols rows -> Matrix e cols rows
493abideJS (Junc (Split a c) (Split b d)) = Split (Junc (abideJS a) (abideJS b)) (Junc (abideJS c) (abideJS d)) -- Junc-Split abide law
493abideJS (Junc (Split a c) (Split b d)) = Split (Junc (abideJS a) (abideJS b)) (Junc (abideJS c) (abideJS d)) -- Junc-Split abide law
494abideJS Empty = Empty
494abideJS Empty = Empty
495−abideJS (One e) = (One e)
495+abideJS (One e) = One e
496abideJS (Junc a b) = Junc (abideJS a) (abideJS b)
496abideJS (Junc a b) = Junc (abideJS a) (abideJS b)
497abideJS (Split a b) = Split (abideJS a) (abideJS b)
497abideJS (Split a b) = Split (abideJS a) (abideJS b)
498
498
@@ -501,7 +501,7 @@ abideJS (Split a b) = Split (abideJS a) (abideJS b)
501abideSJ :: Matrix e cols rows -> Matrix e cols rows
501abideSJ :: Matrix e cols rows -> Matrix e cols rows
502abideSJ (Split (Junc a b) (Junc c d)) = Junc (Split (abideSJ a) (abideSJ c)) (Split (abideSJ b) (abideSJ d)) -- Split-Junc abide law
502abideSJ (Split (Junc a b) (Junc c d)) = Junc (Split (abideSJ a) (abideSJ c)) (Split (abideSJ b) (abideSJ d)) -- Split-Junc abide law
503abideSJ Empty = Empty
503abideSJ Empty = Empty
504−abideSJ (One e) = (One e)
504+abideSJ (One e) = One e
505abideSJ (Junc a b) = Junc (abideSJ a) (abideSJ b)
505abideSJ (Junc a b) = Junc (abideSJ a) (abideSJ b)
506abideSJ (Split a b) = Split (abideSJ a) (abideSJ b)
506abideSJ (Split a b) = Split (abideSJ a) (abideSJ b)
507
507
@@ -515,20 +515,13 @@ tr (Split a b) = Junc (tr a) (tr b)
515
515
516-- Selective 'select' operator
516-- Selective 'select' operator
517
517
518−select ::
518+select :: (Bounded a1, Bounded b, Enum a1, Enum b, Num e, Ord e,
519− ( Num e,
520− Bounded a1,
521− Bounded b,
522− Enum a1,
523− Enum b,
524− Ord e,
525− KnownNat (Count a2),
526− KnownNat (Count rows),
519+ KnownNat (Count a2), KnownNat (Count rows), FromLists e rows a2,
527− FromLists e rows a2,
528− FromLists e rows rows,
520+ FromLists e rows rows, Eq b) =>
529− Eq b
530− ) => Matrix e cols (Either a2 rows) -> (a1 -> b) -> Matrix e cols rows
521+ Matrix e cols (Either a2 rows) -> (a1 -> b) -> Matrix e cols rows
522+select m y =
523+ let f = fromF y
531−select m y = (junc (fromF y) identity) `comp` m
524+ in junc f identity `comp` m
532
525
533-- McCarthy's Conditional
526-- McCarthy's Conditional
534
527
src/Utils.hs+2−1
@@ -1,7 +1,8 @@
1module Utils
1module Utils
2 ( Natural(..),
2 ( Natural(..),
3 nat,
3 nat,
4− coerceNat
4+ coerceNat,
5+ coerceNat2
5 )
6 )
6 where
7 where
7
8
src/Utils/Internal.hs+5−1
@@ -7,7 +7,8 @@
7module Utils.Internal
7module Utils.Internal
8 ( Natural(..),
8 ( Natural(..),
9 nat,
9 nat,
10− coerceNat
10+ coerceNat,
11+ coerceNat2
11 )
12 )
12 where
13 where
13
14
@@ -27,6 +28,9 @@ nat i = let nat = fromInteger (natVal (Proxy :: Proxy n))
27coerceNat :: (Int -> Int -> Int) -> (Natural a -> Natural b -> Natural c)
28coerceNat :: (Int -> Int -> Int) -> (Natural a -> Natural b -> Natural c)
28coerceNat = coerce
29coerceNat = coerce
29
30
31+coerceNat2 :: ((Int, Int) -> Int -> Int) -> ((Natural a, Natural b) -> Natural c -> Natural d)
32+coerceNat2 = coerce
33+
30instance KnownNat n => Bounded (Natural n) where
34instance KnownNat n => Bounded (Natural n) where
31 minBound = Nat 0
35 minBound = Nat 0
32 maxBound = Nat $ fromInteger (natVal (Proxy :: Proxy n))
36 maxBound = Nat $ fromInteger (natVal (Proxy :: Proxy n))