1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Declarations
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
11-- | Data types for modules and declarations
13-----------------------------------------------------------------------------
15{-# LANGUAGE DeriveDataTypeable #-}
17module Language.PureScript.Declarations where
19import Language.PureScript.Values
20import Language.PureScript.Types
21import Language.PureScript.Names
22import Language.PureScript.Kinds
23import Language.PureScript.CodeGen.JS.AST
24import Language.PureScript.Environment
26import qualified Data.Data as D
29-- A precedence level for an infix operator
31type Precedence = Integer
34-- Associativity for infix operators
36data Associativity = Infixl | Infixr deriving (D.Data, D.Typeable)
38instance Show Associativity where
39 show Infixl = "infixl"
40 show Infixr = "infixr"
43-- Fixity data for infix operators
45data Fixity = Fixity Associativity Precedence deriving (Show, D.Data, D.Typeable)
48-- A module declaration, consisting of a module name, a list of declarations, and a list of the
49-- declarations that are explicitly imported. If the export list is Nothing, everything is exported.
51data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
54-- An item in a list of explicit imports or exports
58 -- A type constructor with data constructors
60 = TypeRef ProperName (Maybe [ProperName])
68 | TypeClassRef ProperName
70 -- A type class instance, created during typeclass desugaring (name, class name, instance types)
72 | TypeInstanceRef Ident
73 deriving (Show, Eq, D.Data, D.Typeable)
76-- The data type of declarations
80 -- A data type declaration (name, arguments, data constructors)
82 = DataDeclaration ProperName [String] [(ProperName, [Type])]
84 -- A minimal mutually recursive set of data type declarations
86 | DataBindingGroupDeclaration [Declaration]
88 -- A type synonym declaration (name, arguments, type)
90 | TypeSynonymDeclaration ProperName [String] Type
92 -- A type declaration for a value (name, ty)
94 | TypeDeclaration Ident Type
96 -- A value declaration (name, top-level binders, optional guard, value)
98 | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
100 -- A minimal mutually recursive set of value declarations
102 | BindingGroupDeclaration [(Ident, NameKind, Value)]
104 -- A foreign import declaration (type, name, optional inline Javascript, type)
106 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
108 -- A data type foreign import (name, kind)
110 | ExternDataDeclaration ProperName Kind
112 -- A type class instance foreign import
114 | ExternInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type]
116 -- A fixity declaration (fixity data, operator name)
118 | FixityDeclaration Fixity String
120 -- A module import (module name, optional set of identifiers to import)
122 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
124 -- A type class declaration (name, argument, member declarations)
126 | TypeClassDeclaration ProperName [String] [Declaration]
128 -- A type instance declaration (name, dependencies, class name, instance types, member
131 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
132 deriving (Show, D.Data, D.Typeable)
135-- Test if a declaration is a value declaration
137isValueDecl :: Declaration -> Bool
138isValueDecl ValueDeclaration{} = True
142-- Test if a declaration is a data type or type synonym declaration
144isDataDecl :: Declaration -> Bool
145isDataDecl DataDeclaration{} = True
146isDataDecl TypeSynonymDeclaration{} = True
150-- Test if a declaration is a module import
152isImportDecl :: Declaration -> Bool
153isImportDecl ImportDeclaration{} = True
154isImportDecl _ = False
157-- Test if a declaration is a data type foreign import
159isExternDataDecl :: Declaration -> Bool
160isExternDataDecl ExternDataDeclaration{} = True
161isExternDataDecl _ = False
164-- Test if a declaration is a type class instance foreign import
166isExternInstanceDecl :: Declaration -> Bool
167isExternInstanceDecl ExternInstanceDeclaration{} = True
168isExternInstanceDecl _ = False
171-- Test if a declaration is a fixity declaration
173isFixityDecl :: Declaration -> Bool
174isFixityDecl FixityDeclaration{} = True
175isFixityDecl _ = False
178-- Test if a declaration is a foreign import
180isExternDecl :: Declaration -> Bool
181isExternDecl ExternDeclaration{} = True
182isExternDecl _ = False
185-- Test if a declaration is a type class or instance declaration
187isTypeClassDeclaration :: Declaration -> Bool
188isTypeClassDeclaration TypeClassDeclaration{} = True
189isTypeClassDeclaration TypeInstanceDeclaration{} = True
190isTypeClassDeclaration _ = False
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list