aboutsummaryrefslogtreecommitdiff
path: root/src/CHAD/Interpreter
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-11-27 21:30:17 +0100
committerTom Smeding <tom@tomsmeding.com>2025-11-27 21:30:17 +0100
commit20f7d7be13cd7869b338f98d1ab3fd33e8bbfb3e (patch)
treea21c90034a02cdeb7240563dbbab355e49622d0a /src/CHAD/Interpreter
parentae634c056b500a568b2d89b7f8e225404a2c0c62 (diff)
WIP user-specified custom typesuser-types
The big roadblock encountered is that accumulation wants addition of monoids to be elementwise float addition; this fundamentally clashes with the concept of a user type with a custom zero and plus.
Diffstat (limited to 'src/CHAD/Interpreter')
-rw-r--r--src/CHAD/Interpreter/Rep.hs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/CHAD/Interpreter/Rep.hs b/src/CHAD/Interpreter/Rep.hs
index fadc6be..32a1a48 100644
--- a/src/CHAD/Interpreter/Rep.hs
+++ b/src/CHAD/Interpreter/Rep.hs
@@ -27,6 +27,7 @@ type family Rep t where
Rep (TArr n t) = Array n (Rep t)
Rep (TScal sty) = ScalRep sty
Rep (TAccum t) = RepAc t
+ Rep (TUser t) = Rep (UserRep t)
-- Mutable, represents monoid types t.
type family RepAc t where
@@ -36,6 +37,7 @@ type family RepAc t where
RepAc (TMaybe t) = IORef (Maybe (RepAc t))
RepAc (TArr n t) = Array n (RepAc t)
RepAc (TScal sty) = IORef (ScalRep sty)
+ RepAc (TUser t) = IORef (Rep (UserRep t))
newtype Value t = Value { unValue :: Rep t }
@@ -73,6 +75,8 @@ showValue d (STScal sty) x = case sty of
STI64 -> showsPrec d x
STBool -> showsPrec d x
showValue _ (STAccum t) _ = showString $ "<accumulator for " ++ ppSMTy 0 t ++ ">"
+showValue d (STUser t) x =
+ showParen (d > 10) $ showString ("User[" ++ show (typeOfProxy t) ++ "] ") . showValue 11 (userRepTy t) x
showEnv :: SList STy env -> SList Value env -> String
showEnv = \env vals -> "[" ++ intercalate ", " (showEntries env vals) ++ "]"
@@ -100,6 +104,7 @@ rnfRep (STScal t) x = case t of
STF64 -> rnf x
STBool -> rnf x
rnfRep STAccum{} _ = error "Cannot rnf accumulators"
+rnfRep (STUser t) x = rnfRep (userRepTy t) x
instance KnownTy t => NFData (Value t) where
rnf (Value x) = rnfRep (knownTy @t) x