m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/Abs.hs
blob: 2380fa1641ab9e10e34ef11d8912b7bc8bfbfdcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Abs where

import Parser.AbsSchmim
import Data.Map.Lazy

type Env = Map Ident Val

data Val
    = VNum Integer
    | VAbs Ident Type Env Exp
    | VTr
    | VFl
    | VVrnt Ident Val Type
    | VTpl [Val]
    | VNil Type
    | VCons Val Val
  deriving (Eq, Ord, Read)

instance Show Val where
    show (VNum n) = show n
    show (VAbs x t _ _) = "#(lambda " ++ (show x) ++ " : " ++ (show t) ++ ")"
    show (VTr) = "true"
    show (VFl) = "false"
    show (VVrnt (Ident l) v _) = "<" ++ l ++ " " ++ (show v) ++ ">"
    show (VTpl vs) = "{" ++ (show' vs) ++ "}"
    show (VNil t) = "nil"
    show (VCons v1 v2) = "(cons " ++ (show v1) ++ " " ++ (show v2) ++ ")"

show' = cleanup . Prelude.foldl (\s v -> s ++ (show v) ++ ", ") ""
    where cleanup [] = ""
          cleanup l = init $ init l