From e97817e947520c40c9520618c5d5d56747e4c0f1 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Thu, 24 Apr 2014 13:41:07 +0200 Subject: build with bidirectional type inference --- lib/Numeric/Container.hs | 14 +++++++++- 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 @@ module Numeric.Container ( -- * Basic functions module Data.Packed, - konst, -- build, + konst, build, constant, linspace, diag, ident, ctrans, @@ -188,3 +188,15 @@ instance Container Vector e => Konst e (Int,Int) Matrix where konst = konst' +class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f + where + build :: d -> f -> c e + +instance Container Vector e => Build Int (e -> e) Vector e + where + build = build' + +instance Container Matrix e => Build (Int,Int) (e -> e -> e) Matrix e + where + build = build' + 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 type instance ElementOf (Matrix a) = a ------------------------------------------------------------ -{- -class Build f where - build' :: BoundsOf f -> f -> ContainerOf f - - -#if MIN_VERSION_base(4,7,0) --- ghc >= 7.7 considers: --- --- > a -> a --- > b -> b -> b --- --- to overlap -type family BoundsOf x where - BoundsOf (a -> a) = Int - BoundsOf (a->a->a) = (Int,Int) -type family ContainerOf x where - ContainerOf (a->a) = Vector a - ContainerOf (a->a->a) = Matrix a -#else -type family BoundsOf x -type family ContainerOf x -type instance BoundsOf (a->a) = Int -type instance BoundsOf (a->a->a) = (Int,Int) -type instance ContainerOf (a->a) = Vector a -type instance ContainerOf (a->a->a) = Matrix a -#endif - - -instance (Element a, Num a) => Build (a->a) where - build' = buildV - -instance (Element a, -#if MIN_VERSION_base(4,7,0) - BoundsOf (a -> a -> a) ~ (Int,Int), - ContainerOf (a -> a -> a) ~ Matrix a, -#endif - Num a) - => Build (a->a->a) where - build' = buildM - --} buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ] where rs = map fromIntegral [0 .. (rc-1)] @@ -551,27 +510,6 @@ buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ] buildV n f = fromList [f k | k <- ks] where ks = map fromIntegral [0 .. (n-1)] -{- - ----------------------------------------------------- --- experimental - -class Konst s where - konst' :: Element e => e -> s -> ContainerOf' s e - -type family ContainerOf' x y - -type instance ContainerOf' Int a = Vector a -type instance ContainerOf' (Int,Int) a = Matrix a - -instance Konst Int where - konst' = constantD - -instance Konst (Int,Int) where - konst' k (r,c) = reshape c $ konst' k (r*c) - --} - -------------------------------------------------------- -- | conjugate transpose ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e -- cgit v1.2.3