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 (Show, D.Data, D.Typeable)
39-- Fixity data for infix operators
41data Fixity = Fixity Associativity Precedence deriving (Show, D.Data, D.Typeable)
44-- A module declaration, consisting of a module name, a list of declarations, and a list of the
45-- declarations that are explicitly imported. If the export list is Nothing, everything is exported.
47data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
50-- An item in a list of explicit imports or exports
54 -- A type constructor with data constructors
56 = TypeRef ProperName (Maybe [ProperName])
64 | TypeClassRef ProperName
66 -- A type class instance, created during typeclass desugaring (name, class name, instance types)
68 | TypeInstanceRef Ident
69 deriving (Show, Eq, D.Data, D.Typeable)
72-- The data type of declarations
76 -- A data type declaration (name, arguments, data constructors)
78 = DataDeclaration ProperName [String] [(ProperName, [Type])]
80 -- A minimal mutually recursive set of data type declarations
82 | DataBindingGroupDeclaration [Declaration]
84 -- A type synonym declaration (name, arguments, type)
86 | TypeSynonymDeclaration ProperName [String] Type
88 -- A type declaration for a value (name, ty)
90 | TypeDeclaration Ident Type
92 -- A value declaration (name, top-level binders, optional guard, value)
94 | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
96 -- A minimal mutually recursive set of value declarations
98 | BindingGroupDeclaration [(Ident, NameKind, Value)]
100 -- A foreign import declaration (type, name, optional inline Javascript, type)
102 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
104 -- A data type foreign import (name, kind)
106 | ExternDataDeclaration ProperName Kind
108 -- A type class instance foreign import
110 | ExternInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type]
112 -- A fixity declaration (fixity data, operator name)
114 | FixityDeclaration Fixity String
116 -- A module import (module name, optional set of identifiers to import)
118 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
120 -- A type class declaration (name, argument, member declarations)
122 | TypeClassDeclaration ProperName [String] [Declaration]
124 -- A type instance declaration (name, dependencies, class name, instance types, member
127 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
128 deriving (Show, D.Data, D.Typeable)
131-- Test if a declaration is a value declaration
133isValueDecl :: Declaration -> Bool
134isValueDecl ValueDeclaration{} = True
138-- Test if a declaration is a data type or type synonym declaration
140isDataDecl :: Declaration -> Bool
141isDataDecl DataDeclaration{} = True
142isDataDecl TypeSynonymDeclaration{} = True
146-- Test if a declaration is a module import
148isImportDecl :: Declaration -> Bool
149isImportDecl ImportDeclaration{} = True
150isImportDecl _ = False
153-- Test if a declaration is a data type foreign import
155isExternDataDecl :: Declaration -> Bool
156isExternDataDecl ExternDataDeclaration{} = True
157isExternDataDecl _ = False
160-- Test if a declaration is a type class instance foreign import
162isExternInstanceDecl :: Declaration -> Bool
163isExternInstanceDecl ExternInstanceDeclaration{} = True
164isExternInstanceDecl _ = False
167-- Test if a declaration is a fixity declaration
169isFixityDecl :: Declaration -> Bool
170isFixityDecl FixityDeclaration{} = True
171isFixityDecl _ = False
174-- Test if a declaration is a foreign import
176isExternDecl :: Declaration -> Bool
177isExternDecl ExternDeclaration{} = True
178isExternDecl _ = False
181-- Test if a declaration is a type class or instance declaration
183isTypeClassDeclaration :: Declaration -> Bool
184isTypeClassDeclaration TypeClassDeclaration{} = True
185isTypeClassDeclaration TypeInstanceDeclaration{} = True
186isTypeClassDeclaration _ = 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