summaryrefslogtreecommitdiff
path: root/src/Interpreter/Rep.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Interpreter/Rep.hs')
-rw-r--r--src/Interpreter/Rep.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/Interpreter/Rep.hs b/src/Interpreter/Rep.hs
index 1ded773..7add442 100644
--- a/src/Interpreter/Rep.hs
+++ b/src/Interpreter/Rep.hs
@@ -2,6 +2,8 @@
{-# LANGUAGE TypeFamilies #-}
module Interpreter.Rep where
+import Data.IORef
+import qualified Data.Vector.Mutable as MV
import GHC.TypeError
import Array
@@ -12,6 +14,22 @@ type family Rep t where
Rep TNil = ()
Rep (TPair a b) = (Rep a, Rep b)
Rep (TEither a b) = Either (Rep a) (Rep b)
+ Rep (TMaybe t) = Maybe (Rep t)
Rep (TArr n t) = Array n (Rep t)
Rep (TScal sty) = ScalRep sty
- Rep (TAccum t) = TypeError (Text "Accumulator in Rep")
+ Rep (TAccum t) = IORef (RepAc t)
+
+type family RepAc t where
+ RepAc TNil = ()
+ RepAc (TPair a b) = (RepAc a, RepAc b)
+ -- This is annoying when working with values of type 'RepAc t', because
+ -- failing a pattern match does not generate negative type information.
+ -- However, it works, saves us from having to defining a LEither type
+ -- first-class in the type system with
+ -- Rep (LEither a b) = Maybe (Either a b)
+ -- and it's not even incorrect, in a way.
+ RepAc (TMaybe (TEither a b)) = IORef (Maybe (Either (RepAc a) (RepAc b)))
+ RepAc (TMaybe t) = IORef (Maybe (RepAc t))
+ RepAc (TArr n t) = (Shape n, MV.IOVector (RepAc t))
+ RepAc (TScal sty) = IORef (ScalRep sty)
+ RepAc (TAccum t) = TypeError (Text "Nested accumulators")