2 import "JavaBuiltin" as Java
4 @JavaType "org.simantics.scl.compiler.dynamic.SafeDynamic"
6 @FieldNames [type_, value]
7 SafeDynamic Type Dynamic
9 toSafeDynamic :: Typeable a => a -> SafeDynamic
10 toSafeDynamic val = SafeDynamic (typeOf val) (toDynamic val)
12 fromSafeDynamic :: Typeable a => SafeDynamic -> Maybe a
13 fromSafeDynamic (SafeDynamic type_ value) =
14 if type_ == typeOfProxy (TypeProxy :: TypeProxy a)
15 then Just (Java.unsafeCoerce value)
18 forgetType :: SafeDynamic -> Dynamic
19 forgetType (SafeDynamic _ value) = value
21 typeOfSafeDynamic :: SafeDynamic -> Type
22 typeOfSafeDynamic (SafeDynamic t _) = t