git.iko.soy/rowtype-yoga/purescript-native
on c7d7bf7 help sign in
96 lines 2.8 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Language.PureScript.TypeClassDictionaries
4-- Copyright : (c) 2014 Phil Freeman
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- |
12--
13-----------------------------------------------------------------------------
15{-# LANGUAGE DeriveDataTypeable #-}
17module Language.PureScript.TypeClassDictionaries where
19import Data.Data
21import Language.PureScript.Names
22import Language.PureScript.Types
24-- |
25-- Data representing a type class dictionary which is in scope
26--
27data TypeClassDictionaryInScope
28 = TypeClassDictionaryInScope {
29 -- |
30 -- The identifier with which the dictionary can be accessed at runtime
31 --
32 tcdName :: Qualified Ident
33 -- |
34 -- The name of the type class to which this type class instance applies
35 --
36 , tcdClassName :: Qualified ProperName
37 -- |
38 -- The types to which this type class instance applies
39 --
40 , tcdInstanceTypes :: [Type]
41 -- |
42 -- Type class dependencies which must be satisfied to construct this dictionary
43 --
44 , tcdDependencies :: Maybe [Constraint]
45 -- |
46 -- The type of this dictionary
47 --
48 , tcdType :: TypeClassDictionaryType
49 -- |
50 -- Is this instance exported by its module?
51 --
52 , tcdExported :: Bool
53 } deriving (Show, Data, Typeable)
55-- |
56-- The type of a type class dictionary
57--
58data TypeClassDictionaryType
59 -- |
60 -- A regular type class dictionary
61 --
62 = TCDRegular
63 -- |
64 -- A type class dictionary which is an alias for an imported dictionary from another module
65 --
66 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
68-- |
69-- A simplified representation of expressions which are used to represent type
70-- class dictionaries at runtime, which can be compared for equality
71--
72data DictionaryValue
73 -- |
74 -- A dictionary which is brought into scope by a local constraint
75 --
76 = LocalDictionaryValue (Qualified Ident)
77 -- |
78 -- A dictionary which is brought into scope by an instance declaration
79 --
80 | GlobalDictionaryValue (Qualified Ident)
81 -- |
82 -- A dictionary which depends on other dictionaries
83 --
84 | DependentDictionaryValue (Qualified Ident) [DictionaryValue]
85 -- |
86 -- A subclass dictionary
87 --
88 | SubclassDictionaryValue DictionaryValue (Qualified ProperName) Integer
89 deriving (Show, Ord, Eq)
91-- |
92-- Find the original dictionary which a type class dictionary in scope refers to
93--
94canonicalizeDictionary :: TypeClassDictionaryInScope -> Qualified Ident
95canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDRegular, tcdName = nm }) = nm
96canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDAlias nm }) = nm