on master help sign in
Small fixes
commit321b1ae3e52183284de630bade7ad6ddf89e7db9 authorArmando Santos <armandoifsantos@gmail.com> dateSat 28 Dec 2019, 19:53 (7 years ago) parentd6c0c5d
5 files changed+32−29
app/Main.hs+6 src/Matrix/Nat.hs+7−8 src/Matrix/Type.hs+12−19 src/Utils.hs+2−1 src/Utils/Internal.hs+5−1
app/Main.hs+6
@@ -29,8 +29,13 @@ secondChoice = fromF switch
2929sumSS :: Natural 6 -> Natural 6 -> Natural 12
3030sumSS = coerceNat (+)
3131
32+mulSS :: Natural 6 -> Natural 6 -> Natural 36
33+mulSS = coerceNat (*)
34+
3235sumSSM = fromF' (uncurry sumSS)
3336
37+mulSSM3 = fromF' (mulSS (Nat 3))
38+
3439die :: Dist (Natural 6) 6
3540die = uniform [nat @6 1 .. nat 6]
3641
@@ -39,4 +44,5 @@ main = do
3944 prettyPrint (p1 @Double @1 `comp` secondChoice `comp` firstChoice)
4045 prettyPrint (sumSSM `comp` khatri die die)
4146 prettyPrint (bang `comp` sumSSM `comp` khatri die die)
47+ prettyPrint firstPhase
4248
src/Matrix/Nat.hs+7−8
@@ -430,14 +430,13 @@ tr (M m) = M (I.tr m)
430430
431431-- Selective 'select' operator
432432
433−select
434− :: (Num e, Bounded a1, Bounded b, Enum a1, Enum b, Ord e,
435− KnownNat (I.Count a2), KnownNat (I.Count (I.FromNat rows1)),
436− I.FromLists e (I.FromNat rows1) a2,
437− I.FromLists e (I.FromNat rows1) (I.FromNat rows1), Eq b,
438− I.FromNat cols1 ~ I.FromNat cols2,
439− I.FromNat rows2 ~ Either a2 (I.FromNat rows1)) =>
440− Matrix e cols1 rows2 -> (a1 -> b) -> Matrix e cols2 rows1
433+select :: (Bounded a1, Bounded b, Enum a1, Enum b, Num e, Ord e,
434+ KnownNat (I.Count a2), KnownNat (I.Count (I.FromNat rows1)),
435+ I.FromLists e (I.FromNat rows1) a2,
436+ I.FromLists e (I.FromNat rows1) (I.FromNat rows1), Eq b,
437+ I.FromNat cols1 ~ I.FromNat cols2,
438+ I.FromNat rows2 ~ Either a2 (I.FromNat rows1)) =>
439+ Matrix e cols1 rows2 -> (a1 -> b) -> Matrix e cols2 rows1
441440select (M m) y = M (I.select m y)
442441
443442-- McCarthy's Conditional
src/Matrix/Type.hs+12−19
@@ -226,8 +226,8 @@ instance {-# OVERLAPPING #-} FromLists e () () where
226226 fromLists _ = error "Wrong dimensions"
227227
228228instance (FromLists e cols ()) => FromLists e (Either () cols) () where
229− fromLists [(h : t)] = Junc (One h) (fromLists [t])
230− fromLists _ = error "Wrong dimensions"
229+ fromLists [h : t] = Junc (One h) (fromLists [t])
230+ fromLists _ = error "Wrong dimensions"
231231
232232instance (FromLists e () rows) => FromLists e () (Either () rows) where
233233 fromLists ([h] : t) = Split (One h) (fromLists t)
@@ -296,7 +296,7 @@ fromF f =
296296 buildList l r = take r l : buildList (drop r l) r
297297
298298fromF' ::
299− forall a b cols rows e.
299+ forall a b e.
300300 ( Bounded a,
301301 Bounded b,
302302 Enum a,
@@ -492,7 +492,7 @@ infixl 4 ><
492492abideJS :: Matrix e cols rows -> Matrix e cols rows
493493abideJS (Junc (Split a c) (Split b d)) = Split (Junc (abideJS a) (abideJS b)) (Junc (abideJS c) (abideJS d)) -- Junc-Split abide law
494494abideJS Empty = Empty
495−abideJS (One e) = (One e)
495+abideJS (One e) = One e
496496abideJS (Junc a b) = Junc (abideJS a) (abideJS b)
497497abideJS (Split a b) = Split (abideJS a) (abideJS b)
498498
@@ -501,7 +501,7 @@ abideJS (Split a b) = Split (abideJS a) (abideJS b)
501501abideSJ :: Matrix e cols rows -> Matrix e cols rows
502502abideSJ (Split (Junc a b) (Junc c d)) = Junc (Split (abideSJ a) (abideSJ c)) (Split (abideSJ b) (abideSJ d)) -- Split-Junc abide law
503503abideSJ Empty = Empty
504−abideSJ (One e) = (One e)
504+abideSJ (One e) = One e
505505abideSJ (Junc a b) = Junc (abideSJ a) (abideSJ b)
506506abideSJ (Split a b) = Split (abideSJ a) (abideSJ b)
507507
@@ -515,20 +515,13 @@ tr (Split a b) = Junc (tr a) (tr b)
515515
516516-- Selective 'select' operator
517517
518−select ::
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),
527− FromLists e rows a2,
528− FromLists e rows rows,
529− Eq b
530− ) => Matrix e cols (Either a2 rows) -> (a1 -> b) -> Matrix e cols rows
531−select m y = (junc (fromF y) identity) `comp` m
518+select :: (Bounded a1, Bounded b, Enum a1, Enum b, Num e, Ord e,
519+ KnownNat (Count a2), KnownNat (Count rows), FromLists e rows a2,
520+ FromLists e rows rows, Eq b) =>
521+ Matrix e cols (Either a2 rows) -> (a1 -> b) -> Matrix e cols rows
522+select m y =
523+ let f = fromF y
524+ in junc f identity `comp` m
532525
533526-- McCarthy's Conditional
534527
src/Utils.hs+2−1
@@ -1,7 +1,8 @@
11module Utils
22 ( Natural(..),
33 nat,
4− coerceNat
4+ coerceNat,
5+ coerceNat2
56 )
67 where
78
src/Utils/Internal.hs+5−1
@@ -7,7 +7,8 @@
77module Utils.Internal
88 ( Natural(..),
99 nat,
10− coerceNat
10+ coerceNat,
11+ coerceNat2
1112 )
1213 where
1314
@@ -27,6 +28,9 @@ nat i = let nat = fromInteger (natVal (Proxy :: Proxy n))
2728coerceNat :: (Int -> Int -> Int) -> (Natural a -> Natural b -> Natural c)
2829coerceNat = coerce
2930
31+coerceNat2 :: ((Int, Int) -> Int -> Int) -> ((Natural a, Natural b) -> Natural c -> Natural d)
32+coerceNat2 = coerce
33+
3034instance KnownNat n => Bounded (Natural n) where
3135 minBound = Nat 0
3236 maxBound = Nat $ fromInteger (natVal (Proxy :: Proxy n))