Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ Syntax for types

  • Loading branch information...
commit da1bab7ff979449e3bc39da1efc5c1881675fbde 1 parent fd17d08
@Averethel authored
Showing with 43 additions and 0 deletions.
  1. +4 −0 Types.hs
  2. +39 −0 Types/Base.hs
View
4 Types.hs
@@ -0,0 +1,4 @@
+module Types (
+ Type(..)
+) where
+ import Types.Base
View
39 Types/Base.hs
@@ -0,0 +1,39 @@
+module Types.Base where
+ import Utils.Iseq
+
+ data Type =
+ Tint
+ | Tbool
+ | Tunit
+ | Tvar String
+ | Tlist Type
+ | Tref Type
+ | Ttuple [Type]
+ | Tfun [Type] Type
+ deriving Eq
+
+ isAtomicType :: Type -> Bool
+ isAtomicType (Tfun _ _) = False
+ isAtomicType (Tlist _) = False
+ isAtomicType (Tref _) = False
+ isAtomicType _ = True
+
+ pprAType :: Type -> Iseq
+ pprAType t
+ | isAtomicType t = pprType t
+ | otherwise = iStr "(" `iAppend` pprType t `iAppend` iStr ")"
+
+ pprType :: Type -> Iseq
+ pprType Tint = iStr "int"
+ pprType Tbool = iStr "bool"
+ pprType Tunit = iStr "unit"
+ pprType (Tvar v) = iStr v
+ pprType (Tlist t) = pprAType t `iAppend` iStr " list"
+ pprType (Tref t) = pprType t `iAppend` iStr " ref"
+ pprType (Ttuple ts) = iConcat [ iStr "(", iInterleave (iStr ", ") $
+ map pprAType ts, iStr ")" ]
+ pprType (Tfun ts t) = iConcat [ iInterleave (iStr " -> ") $ map pprAType ts,
+ iStr " -> ", pprType t ]
+
+ instance Show Type where
+ show = show . pprType
Please sign in to comment.
Something went wrong with that request. Please try again.