Commit 4d5b1bf7 authored by rl@cse.unsw.edu.au's avatar rl@cse.unsw.edu.au
Browse files

PA is now a class instead of a record

parent ed5b5248
module Data.Array.Parallel.Lifted (
PArray(..), PA(..),
(:->), ($:), ($:^), closurePA
(:->), ($:), ($:^)
) where
import Data.Array.Parallel.Lifted.PArray
......
module Data.Array.Parallel.Lifted.Closure (
(:->)(..), PArray(..),
mkClosure, mkClosureP, ($:), ($:^), closurePA
mkClosure, mkClosureP, ($:), ($:^)
) where
import Data.Array.Parallel.Lifted.PArray
......@@ -10,16 +10,16 @@ infixr 0 $:, $:^
-- |The type of closures
--
data a :-> b = forall e. Clo !(PA e)
!(e -> a -> b)
!(PArray e -> PArray a -> PArray b)
e
data a :-> b = forall e. PA e => Clo !(e -> a -> b)
!(PArray e -> PArray a -> PArray b)
e
-- |Closure construction
--
mkClosure :: forall a b e.
PA e -> (e -> a -> b) -> (PArray e -> PArray a -> PArray b) -> e
-> (a :-> b)
mkClosure :: forall a b e.
PA e => (e -> a -> b)
-> (PArray e -> PArray a -> PArray b)
-> e -> (a :-> b)
{-# INLINE mkClosure #-}
mkClosure = Clo
......@@ -27,21 +27,21 @@ mkClosure = Clo
--
($:) :: forall a b. (a :-> b) -> a -> b
{-# INLINE ($:) #-}
Clo _ f _ e $: a = f e a
Clo f _ e $: a = f e a
-- |Arrays of closures (aka array closures)
--
data instance PArray (a :-> b) = forall e.
AClo !(PA e)
!(e -> a -> b)
!(PArray e -> PArray a -> PArray b)
!(PArray e)
data instance PArray (a :-> b)
= forall e. PA e => AClo !(e -> a -> b)
!(PArray e -> PArray a -> PArray b)
!(PArray e)
-- |Lifted closure construction
--
mkClosureP :: forall a b e.
PA e -> (e -> a -> b) -> (PArray e -> PArray a -> PArray b)
-> PArray e -> PArray (a :-> b)
PA e => (e -> a -> b)
-> (PArray e -> PArray a -> PArray b)
-> PArray e -> PArray (a :-> b)
{-# INLINE mkClosureP #-}
mkClosureP = AClo
......@@ -49,20 +49,11 @@ mkClosureP = AClo
--
($:^) :: forall a b. PArray (a :-> b) -> PArray a -> PArray b
{-# INLINE ($:^) #-}
AClo _ _ f es $:^ as = f es as
AClo _ f es $:^ as = f es as
closure_lengthPA :: PArray (a :-> b) -> Int
{-# INLINE closure_lengthPA #-}
closure_lengthPA (AClo pa _ _ es) = lengthPA pa es
closure_replicatePA :: Int -> (a :-> b) -> PArray (a :-> b)
{-# INLINE closure_replicatePA #-}
closure_replicatePA n (Clo pa f f' e) = AClo pa f f' (replicatePA pa n e)
-- |Closure dictionary
closurePA :: PA (a :-> b)
closurePA = PA {
lengthPA = closure_lengthPA
, replicatePA = closure_replicatePA
}
instance (PA a, PA b) => PA (a :-> b) where
{-# INLINE lengthPA #-}
lengthPA (AClo _ _ es) = lengthPA es
{-# INLINE replicatePA #-}
replicatePA n (Clo f f' e) = AClo f f' (replicatePA n e)
......@@ -8,8 +8,7 @@ data family PArray a
-- |Dictionaries
--
data PA a = PA {
lengthPA :: PArray a -> Int
, replicatePA :: Int -> a -> PArray a
}
class PA a where
lengthPA :: PArray a -> Int
replicatePA :: Int -> a -> PArray a
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment