Commit 2e9d99ec authored by rl@cse.unsw.edu.au's avatar rl@cse.unsw.edu.au
Browse files

Isomorphisms for closure conversion

parent 1c9177d2
module Data.Array.Parallel.Base.Closure (
(:->)(..), closure, ($:)
(:->)(..),
closure, ($:),
(:<->:)(..),
to, from,
identity, convArrow
) where
infixr 0 :->
infixr 0 $:
data a :-> b = forall e. Clo !(e -> a -> b) e
infix 1 :<->:
data a :-> b = forall e. !(e -> a -> b) :$ e
closure :: (e -> a -> b) -> e -> (a :-> b)
{-# INLINE closure #-}
closure = Clo
closure = (:$)
($:) :: (a :-> b) -> a -> b
{-# INLINE ($:) #-}
Clo f e $: x = f e x
(f :$ e) $: x = f e x
data a :<->: b = (a -> b) :<->: (b -> a)
to :: a :<->: b -> a -> b
{-# INLINE to #-}
to (f :<->: _) = f
from :: a :<->: b -> b -> a
{-# INLINE from #-}
from (_ :<->: f) = f
identity :: a :<->: a
identity = id :<->: id
toClosure :: a :<->: a' -> b :<->: b' -> (a -> b) -> (a' :-> b')
{-# INLINE toClosure #-}
toClosure isoa isob f = (const (to isob . f . from isoa)) :$ ()
fromClosure :: a :<->: a' -> b :<->: b' -> (a' :-> b') -> (a -> b)
{-# INLINE fromClosure #-}
fromClosure isoa isob (f :$ e) = from isob . f e . to isoa
convArrow :: a :<->: a' -> b :<->: b' -> (a -> b) :<->: (a' :-> b')
{-# INLINE convArrow #-}
convArrow isoa isob = toClosure isoa isob :<->: fromClosure isoa isob
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