PrettyTypes.hs 1.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
{- |
    Module      :  $Header$
    Description :  TODO
    Copyright   :  (c) 2017        Finn Teegen
    License     :  BSD-3-clause

    Maintainer  :  bjp@informatik.uni-kiel.de
    Stability   :  experimental
    Portability :  portable

   TODO
-}
Finn Teegen's avatar
Finn Teegen committed
13
{-# LANGUAGE CPP #-}
14
15
module Base.PrettyTypes where

Finn Teegen's avatar
Finn Teegen committed
16
17
18
19
#if __GLASGOW_HASKELL__ >= 804
import Prelude hiding ((<>))
#endif

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Data.Maybe (fromMaybe)
import qualified Data.Set as Set (Set, toAscList)

import Curry.Base.Ident (identSupply)
import Curry.Base.Pretty
import Curry.Syntax.Pretty

import Base.CurryTypes
import Base.Types

instance Pretty Type where
  pPrint = ppTypeExpr 0 . fromType identSupply

instance Pretty Pred where
  pPrint = ppConstraint . fromPred identSupply

instance Pretty a => Pretty (Set.Set a) where
  pPrint = parens . list . map pPrint . Set.toAscList

instance Pretty PredType where
  pPrint = ppQualTypeExpr . fromPredType identSupply

instance Pretty DataConstr where
  pPrint (DataConstr i _ _ tys)      = pPrint i <+> hsep (map pPrint tys)
  pPrint (RecordConstr i _ _ ls tys) =     pPrint i
                                       <+> braces (hsep (punctuate comma pLs))
    where
      pLs = zipWith (\l ty -> pPrint l <+> colon <> colon <+> pPrint ty) ls tys

instance Pretty ClassMethod where
  pPrint (ClassMethod f mar pty) =     pPrint f
                                   <>  text "/" <> int (fromMaybe 0 mar)
                                   <+> colon <> colon <+> pPrint pty

instance Pretty TypeScheme where
  pPrint (ForAll _ ty) = pPrint ty

instance Pretty ExistTypeScheme where
  pPrint (ForAllExist _ _ ty) = pPrint ty