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 and a list of declarations
45data Module = Module ModuleName [Declaration] deriving (Show, D.Data, D.Typeable)
48-- The type of a foreign import
52 -- A regular foreign import
56 -- A foreign import which contains inline Javascript as a string literal
60 -- A type class dictionary import, generated during desugaring of type class declarations
62 | TypeClassDictionaryImport
64 -- A type class dictionary member accessor import, generated during desugaring of type class declarations
66 | TypeClassAccessorImport deriving (Show, Eq, D.Data, D.Typeable)
69-- An item in a list of explicit imports
73 -- A type constructor import
75 = TypeImport ProperName (Maybe [ProperName])
77 -- A declaration import
81 -- A type class import
83 | TypeClassImport ProperName
84 deriving (Show, D.Data, D.Typeable)
87-- The data type of declarations
91 -- A data type declaration (name, arguments, data constructors)
93 = DataDeclaration ProperName [String] [(ProperName, [Type])]
95 -- A minimal mutually recursive set of data type declarations
97 | DataBindingGroupDeclaration [Declaration]
99 -- A type synonym declaration (name, arguments, type)
101 | TypeSynonymDeclaration ProperName [String] Type
103 -- A type declaration for a value (name, ty)
105 | TypeDeclaration Ident Type
107 -- A value declaration (name, top-level binders, optional guard, value)
109 | ValueDeclaration Ident [Binder] (Maybe Guard) Value
111 -- A minimal mutually recursive set of value declarations
113 | BindingGroupDeclaration [(Ident, Value)]
115 -- A foreign import declaration (type, name, optional inline Javascript, type)
117 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
119 -- A data type foreign import (name, kind)
121 | ExternDataDeclaration ProperName Kind
123 -- A fixity declaration (fixity data, operator name)
125 | FixityDeclaration Fixity String
127 -- A module import (module name, optional set of identifiers to import)
129 | ImportDeclaration ModuleName (Maybe [ImportType])
131 -- A type class declaration (name, argument, member declarations)
133 | TypeClassDeclaration ProperName [String] [Declaration]
135 -- A type instance declaration (dependencies, class name, instance type, member declarations)
137 | TypeInstanceDeclaration [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
138 deriving (Show, D.Data, D.Typeable)
141-- Test if a declaration is a value declaration
143isValueDecl :: Declaration -> Bool
144isValueDecl ValueDeclaration{} = True
148-- Test if a declaration is a data type or type synonym declaration
150isDataDecl :: Declaration -> Bool
151isDataDecl DataDeclaration{} = True
152isDataDecl TypeSynonymDeclaration{} = True
156-- Test if a declaration is a module import
158isImportDecl :: Declaration -> Bool
159isImportDecl ImportDeclaration{} = True
160isImportDecl _ = False
163-- Test if a declaration is a data type foreign import
165isExternDataDecl :: Declaration -> Bool
166isExternDataDecl ExternDataDeclaration{} = True
167isExternDataDecl _ = False
170-- Test if a declaration is a fixity declaration
172isFixityDecl :: Declaration -> Bool
173isFixityDecl FixityDeclaration{} = True
174isFixityDecl _ = False
177-- Test if a declaration is a foreign import
179isExternDecl :: Declaration -> Bool
180isExternDecl ExternDeclaration{} = True
181isExternDecl _ = False
184-- Test if a declaration is a type class or instance declaration
186isTypeClassDeclaration :: Declaration -> Bool
187isTypeClassDeclaration TypeClassDeclaration{} = True
188isTypeClassDeclaration TypeInstanceDeclaration{} = True
189isTypeClassDeclaration _ = 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