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
25import qualified Data.Data as D
28-- A precedence level for an infix operator
30type Precedence = Integer
33-- Associativity for infix operators
35data Associativity = Infixl | Infixr deriving (Show, D.Data, D.Typeable)
38-- Fixity data for infix operators
40data Fixity = Fixity Associativity Precedence deriving (Show, D.Data, D.Typeable)
43-- A module declaration, consisting of a module name, a list of declarations, and a list of the
44-- declarations that are explicitly imported. If the export list is Nothing, everything is exported.
46data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
49-- The type of a foreign import
53 -- A regular foreign import
57 -- A foreign import which contains inline Javascript as a string literal
61 -- A type class dictionary import, generated during desugaring of type class declarations
63 | TypeClassDictionaryImport
65 -- A type class dictionary member accessor import, generated during desugaring of type class declarations
67 | TypeClassAccessorImport deriving (Show, Eq, D.Data, D.Typeable)
70-- An item in a list of explicit imports or exports
74 -- A type constructor with data constructors
76 = TypeRef ProperName (Maybe [ProperName])
84 | TypeClassRef ProperName
85 deriving (Show, D.Data, D.Typeable)
88-- The data type of declarations
92 -- A data type declaration (name, arguments, data constructors)
94 = DataDeclaration ProperName [String] [(ProperName, [Type])]
96 -- A minimal mutually recursive set of data type declarations
98 | DataBindingGroupDeclaration [Declaration]
100 -- A type synonym declaration (name, arguments, type)
102 | TypeSynonymDeclaration ProperName [String] Type
104 -- A type declaration for a value (name, ty)
106 | TypeDeclaration Ident Type
108 -- A value declaration (name, top-level binders, optional guard, value)
110 | ValueDeclaration Ident [Binder] (Maybe Guard) Value
112 -- A minimal mutually recursive set of value declarations
114 | BindingGroupDeclaration [(Ident, Value)]
116 -- A foreign import declaration (type, name, optional inline Javascript, type)
118 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
120 -- A data type foreign import (name, kind)
122 | ExternDataDeclaration ProperName Kind
124 -- A fixity declaration (fixity data, operator name)
126 | FixityDeclaration Fixity String
128 -- A module import (module name, optional set of identifiers to import)
130 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
132 -- A type class declaration (name, argument, member declarations)
134 | TypeClassDeclaration ProperName [String] [Declaration]
136 -- A type instance declaration (dependencies, class name, instance type, member declarations)
138 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
139 deriving (Show, D.Data, D.Typeable)
142-- Test if a declaration is a value declaration
144isValueDecl :: Declaration -> Bool
145isValueDecl ValueDeclaration{} = True
149-- Test if a declaration is a data type or type synonym declaration
151isDataDecl :: Declaration -> Bool
152isDataDecl DataDeclaration{} = True
153isDataDecl TypeSynonymDeclaration{} = True
157-- Test if a declaration is a module import
159isImportDecl :: Declaration -> Bool
160isImportDecl ImportDeclaration{} = True
161isImportDecl _ = False
164-- Test if a declaration is a data type foreign import
166isExternDataDecl :: Declaration -> Bool
167isExternDataDecl ExternDataDeclaration{} = True
168isExternDataDecl _ = 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