diff options
Diffstat (limited to 'src/Interpreter/Rep.hs')
-rw-r--r-- | src/Interpreter/Rep.hs | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/Interpreter/Rep.hs b/src/Interpreter/Rep.hs index ac06915..f84f4e7 100644 --- a/src/Interpreter/Rep.hs +++ b/src/Interpreter/Rep.hs @@ -21,28 +21,25 @@ type family Rep t where Rep (TMaybe t) = Maybe (Rep t) Rep (TArr n t) = Array n (Rep t) Rep (TScal sty) = ScalRep sty - Rep (TAccum t) = RepAcSparse t + Rep (TAccum t) = RepAc t --- Mutable, and has a zero. The zero may not be O(1), but RepAcSparse (D2 t) will have an O(1) zero. -type family RepAcSparse t where - RepAcSparse TNil = () - RepAcSparse (TPair a b) = IORef (RepAcSparse a, RepAcSparse b) - RepAcSparse (TEither a b) = TypeError (Text "Non-sparse coproduct is not a monoid") - RepAcSparse (TMaybe t) = IORef (Maybe (RepAcDense t)) -- allow the value to be dense, because the Maybe's zero can be used for the contents +-- Mutable, represents D2 of t. Has an O(1) zero. +type family RepAc t where + RepAc TNil = () + RepAc (TPair a b) = IORef (Maybe (RepAc a, RepAc b)) + RepAc (TEither a b) = IORef (Maybe (Either (RepAc a) (RepAc b))) + RepAc (TMaybe t) = IORef (Maybe (RepAc t)) -- TODO: an empty array is invalid for a zero-dimensional array, so zero-dimensional arrays don't actually have an O(1) zero. - RepAcSparse (TArr n t) = IORef (Array n (RepAcSparse t)) -- empty array is zero - RepAcSparse (TScal sty) = IORef (ScalRep sty) - RepAcSparse (TAccum t) = TypeError (Text "RepAcSparse: Nested accumulators") + RepAc (TArr n t) = IORef (Array n (RepAc t)) -- empty array is zero + RepAc (TScal sty) = RepAcScal sty + RepAc (TAccum t) = TypeError (Text "RepAcSparse: Nested accumulators") --- Immutable, and does not necessarily have a zero. -type family RepAcDense t where - RepAcDense TNil = () - RepAcDense (TPair a b) = (RepAcSparse a, RepAcSparse b) - RepAcDense (TEither a b) = Either (RepAcSparse a) (RepAcSparse b) - -- RepAcDense (TMaybe t) = RepAcSparse (TMaybe t) -- ^ This can be optimised to TMaybe (RepAcSparse t), but that makes accumAddDense very hard to write. And in any case, we don't need it because D2 will not produce Maybe of Maybe. - -- RepAcDense (TArr n t) = Array n (RepAcSparse t) - -- RepAcDense (TScal sty) = ScalRep sty - -- RepAcDense (TAccum t) = TypeError (Text "RepAcDense: Nested accumulators") +type family RepAcScal t where + RepAcScal TI32 = () + RepAcScal TI64 = () + RepAcScal TF32 = IORef Float + RepAcScal TF64 = IORef Double + RepAcScal TBool = () newtype Value t = Value { unValue :: Rep t } |