From ba41cd3fb6ec374ffc6ddfcef785244cac4f924e Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 14 Aug 2022 15:54:34 +0100 Subject: Display types --- src/Ast.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Ast.hs b/src/Ast.hs index 7efdfe1..c2bae9e 100644 --- a/src/Ast.hs +++ b/src/Ast.hs @@ -1,10 +1,21 @@ module Ast where +import Data.List (intercalate) import Text.Parsec (SourcePos) type Ident = String -data Type = Type String | FuncType [Type] (Maybe Type) deriving (Eq, Ord, Show) +data Type = Type String | FuncType [Type] (Maybe Type) deriving (Eq, Ord) + +instance Show Type where + show (Type t) = t + show (FuncType params rtyp) = + "(" ++ (intercalate ", " (fmap show params)) ++ ") -> " ++ case rtyp of + Just t -> show t + Nothing -> "()" + +showList :: [Type] -> String +showList xs = intercalate ", " $ fmap show xs type FuncParam = (Ident, Type, SourcePos) -- cgit v1.2.3