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 | Infix deriving (D.Data, D.Typeable)
38instance Show Associativity where
39 show Infixl = "infixl"
40 show Infixr = "infixr"
44-- Fixity data for infix operators
46data Fixity = Fixity Associativity Precedence deriving (Show, D.Data, D.Typeable)
49-- A module declaration, consisting of a module name, a list of declarations, and a list of the
50-- declarations that are explicitly imported. If the export list is Nothing, everything is exported.
52data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
55-- An item in a list of explicit imports or exports
59 -- A type constructor with data constructors
61 = TypeRef ProperName (Maybe [ProperName])
69 | TypeClassRef ProperName
71 -- A type class instance, created during typeclass desugaring (name, class name, instance types)
73 | TypeInstanceRef Ident
74 deriving (Show, Eq, D.Data, D.Typeable)
77-- The data type of declarations
81 -- A data type declaration (name, arguments, data constructors)
83 = DataDeclaration ProperName [String] [(ProperName, [Type])]
85 -- A minimal mutually recursive set of data type declarations
87 | DataBindingGroupDeclaration [Declaration]
89 -- A type synonym declaration (name, arguments, type)
91 | TypeSynonymDeclaration ProperName [String] Type
93 -- A type declaration for a value (name, ty)
95 | TypeDeclaration Ident Type
97 -- A value declaration (name, top-level binders, optional guard, value)
99 | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
101 -- A minimal mutually recursive set of value declarations
103 | BindingGroupDeclaration [(Ident, NameKind, Value)]
105 -- A foreign import declaration (type, name, optional inline Javascript, type)
107 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
109 -- A data type foreign import (name, kind)
111 | ExternDataDeclaration ProperName Kind
113 -- A type class instance foreign import
115 | ExternInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type]
117 -- A fixity declaration (fixity data, operator name)
119 | FixityDeclaration Fixity String
121 -- A module import (module name, optional set of identifiers to import, optional "qualified as"
124 | ImportDeclaration ModuleName (Maybe [DeclarationRef]) (Maybe ModuleName)
126 -- A type class declaration (name, argument, member declarations)
128 | TypeClassDeclaration ProperName [String] [Declaration]
130 -- A type instance declaration (name, dependencies, class name, instance types, member
133 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
134 deriving (Show, D.Data, D.Typeable)
137-- Test if a declaration is a value declaration
139isValueDecl :: Declaration -> Bool
140isValueDecl ValueDeclaration{} = True
144-- Test if a declaration is a data type or type synonym declaration
146isDataDecl :: Declaration -> Bool
147isDataDecl DataDeclaration{} = True
148isDataDecl TypeSynonymDeclaration{} = True
152-- Test if a declaration is a module import
154isImportDecl :: Declaration -> Bool
155isImportDecl ImportDeclaration{} = True
156isImportDecl _ = False
159-- Test if a declaration is a data type foreign import
161isExternDataDecl :: Declaration -> Bool
162isExternDataDecl ExternDataDeclaration{} = True
163isExternDataDecl _ = False
166-- Test if a declaration is a type class instance foreign import
168isExternInstanceDecl :: Declaration -> Bool
169isExternInstanceDecl ExternInstanceDeclaration{} = True
170isExternInstanceDecl _ = False
173-- Test if a declaration is a fixity declaration
175isFixityDecl :: Declaration -> Bool
176isFixityDecl FixityDeclaration{} = True
177isFixityDecl _ = False
180-- Test if a declaration is a foreign import
182isExternDecl :: Declaration -> Bool
183isExternDecl ExternDeclaration{} = True
184isExternDecl _ = False
187-- Test if a declaration is a type class or instance declaration
189isTypeClassDeclaration :: Declaration -> Bool
190isTypeClassDeclaration TypeClassDeclaration{} = True
191isTypeClassDeclaration TypeInstanceDeclaration{} = True
192isTypeClassDeclaration _ = 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