diff options
Diffstat (limited to 'src/Interpreter/Rep.hs')
-rw-r--r-- | src/Interpreter/Rep.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Interpreter/Rep.hs b/src/Interpreter/Rep.hs index 5c20183..baf38fc 100644 --- a/src/Interpreter/Rep.hs +++ b/src/Interpreter/Rep.hs @@ -3,6 +3,8 @@ {-# LANGUAGE UndecidableInstances #-} module Interpreter.Rep where +import Data.List (intersperse) +import Data.Foldable (toList) import Data.IORef import GHC.TypeError @@ -53,3 +55,23 @@ vPair = liftV2 (,) vUnpair :: Value (TPair a b) -> (Value a, Value b) vUnpair (Value (x, y)) = (Value x, Value y) + +showValue :: Int -> STy t -> Rep t -> ShowS +showValue _ STNil () = showString "()" +showValue _ (STPair a b) (x, y) = showString "(" . showValue 0 a x . showString "," . showValue 0 b y . showString ")" +showValue d (STEither a _) (Left x) = showParen (d > 10) $ showString "Left " . showValue 11 a x +showValue d (STEither _ b) (Right y) = showParen (d > 10) $ showString "Right " . showValue 11 b y +showValue _ (STMaybe _) Nothing = showString "Nothing" +showValue d (STMaybe t) (Just x) = showParen (d > 10) $ showString "Just " . showValue 11 t x +showValue d (STArr _ t) arr = showParen (d > 10) $ + showString "arrayFromList " . showsPrec 11 (arrayShape arr) + . showString " [" + . foldr (.) id (intersperse (showString ",") $ map (showValue 0 t) (toList arr)) + . showString "]" +showValue _ (STScal sty) x = case sty of + STF32 -> shows x + STF64 -> shows x + STI32 -> shows x + STI64 -> shows x + STBool -> shows x +showValue _ STAccum{} _ = error "Cannot show accumulators" |