diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-04-24 13:41:07 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-04-24 13:41:07 +0200 |
commit | e97817e947520c40c9520618c5d5d56747e4c0f1 (patch) | |
tree | d07672113ab9e739ccbbd6b29832ab863bc42525 | |
parent | de0219353ca9631135a3f750cef05b9636bef232 (diff) |
build with bidirectional type inference
-rw-r--r-- | lib/Numeric/Container.hs | 14 | ||||
-rw-r--r-- | lib/Numeric/ContainerBoot.hs | 62 |
2 files changed, 13 insertions, 63 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs index a31acfe..46c2903 100644 --- a/lib/Numeric/Container.hs +++ b/lib/Numeric/Container.hs | |||
@@ -28,7 +28,7 @@ | |||
28 | module Numeric.Container ( | 28 | module Numeric.Container ( |
29 | -- * Basic functions | 29 | -- * Basic functions |
30 | module Data.Packed, | 30 | module Data.Packed, |
31 | konst, -- build, | 31 | konst, build, |
32 | constant, linspace, | 32 | constant, linspace, |
33 | diag, ident, | 33 | diag, ident, |
34 | ctrans, | 34 | ctrans, |
@@ -188,3 +188,15 @@ instance Container Vector e => Konst e (Int,Int) Matrix | |||
188 | where | 188 | where |
189 | konst = konst' | 189 | konst = konst' |
190 | 190 | ||
191 | class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f | ||
192 | where | ||
193 | build :: d -> f -> c e | ||
194 | |||
195 | instance Container Vector e => Build Int (e -> e) Vector e | ||
196 | where | ||
197 | build = build' | ||
198 | |||
199 | instance Container Matrix e => Build (Int,Int) (e -> e -> e) Matrix e | ||
200 | where | ||
201 | build = build' | ||
202 | |||
diff --git a/lib/Numeric/ContainerBoot.hs b/lib/Numeric/ContainerBoot.hs index 8707473..d61633e 100644 --- a/lib/Numeric/ContainerBoot.hs +++ b/lib/Numeric/ContainerBoot.hs | |||
@@ -502,47 +502,6 @@ type instance ElementOf (Vector a) = a | |||
502 | type instance ElementOf (Matrix a) = a | 502 | type instance ElementOf (Matrix a) = a |
503 | 503 | ||
504 | ------------------------------------------------------------ | 504 | ------------------------------------------------------------ |
505 | {- | ||
506 | class Build f where | ||
507 | build' :: BoundsOf f -> f -> ContainerOf f | ||
508 | |||
509 | |||
510 | #if MIN_VERSION_base(4,7,0) | ||
511 | -- ghc >= 7.7 considers: | ||
512 | -- | ||
513 | -- > a -> a | ||
514 | -- > b -> b -> b | ||
515 | -- | ||
516 | -- to overlap | ||
517 | type family BoundsOf x where | ||
518 | BoundsOf (a -> a) = Int | ||
519 | BoundsOf (a->a->a) = (Int,Int) | ||
520 | type family ContainerOf x where | ||
521 | ContainerOf (a->a) = Vector a | ||
522 | ContainerOf (a->a->a) = Matrix a | ||
523 | #else | ||
524 | type family BoundsOf x | ||
525 | type family ContainerOf x | ||
526 | type instance BoundsOf (a->a) = Int | ||
527 | type instance BoundsOf (a->a->a) = (Int,Int) | ||
528 | type instance ContainerOf (a->a) = Vector a | ||
529 | type instance ContainerOf (a->a->a) = Matrix a | ||
530 | #endif | ||
531 | |||
532 | |||
533 | instance (Element a, Num a) => Build (a->a) where | ||
534 | build' = buildV | ||
535 | |||
536 | instance (Element a, | ||
537 | #if MIN_VERSION_base(4,7,0) | ||
538 | BoundsOf (a -> a -> a) ~ (Int,Int), | ||
539 | ContainerOf (a -> a -> a) ~ Matrix a, | ||
540 | #endif | ||
541 | Num a) | ||
542 | => Build (a->a->a) where | ||
543 | build' = buildM | ||
544 | |||
545 | -} | ||
546 | 505 | ||
547 | buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ] | 506 | buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ] |
548 | where rs = map fromIntegral [0 .. (rc-1)] | 507 | where rs = map fromIntegral [0 .. (rc-1)] |
@@ -551,27 +510,6 @@ buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ] | |||
551 | buildV n f = fromList [f k | k <- ks] | 510 | buildV n f = fromList [f k | k <- ks] |
552 | where ks = map fromIntegral [0 .. (n-1)] | 511 | where ks = map fromIntegral [0 .. (n-1)] |
553 | 512 | ||
554 | {- | ||
555 | |||
556 | ---------------------------------------------------- | ||
557 | -- experimental | ||
558 | |||
559 | class Konst s where | ||
560 | konst' :: Element e => e -> s -> ContainerOf' s e | ||
561 | |||
562 | type family ContainerOf' x y | ||
563 | |||
564 | type instance ContainerOf' Int a = Vector a | ||
565 | type instance ContainerOf' (Int,Int) a = Matrix a | ||
566 | |||
567 | instance Konst Int where | ||
568 | konst' = constantD | ||
569 | |||
570 | instance Konst (Int,Int) where | ||
571 | konst' k (r,c) = reshape c $ konst' k (r*c) | ||
572 | |||
573 | -} | ||
574 | |||
575 | -------------------------------------------------------- | 513 | -------------------------------------------------------- |
576 | -- | conjugate transpose | 514 | -- | conjugate transpose |
577 | ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e | 515 | ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e |