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-- An item in a list of explicit imports or exports
53 -- A type constructor with data constructors
55 = TypeRef ProperName (Maybe [ProperName])
63 | TypeClassRef ProperName
64 deriving (Show, Eq, D.Data, D.Typeable)
67-- The data type of declarations
71 -- A data type declaration (name, arguments, data constructors)
73 = DataDeclaration ProperName [String] [(ProperName, [Type])]
75 -- A minimal mutually recursive set of data type declarations
77 | DataBindingGroupDeclaration [Declaration]
79 -- A type synonym declaration (name, arguments, type)
81 | TypeSynonymDeclaration ProperName [String] Type
83 -- A type declaration for a value (name, ty)
85 | TypeDeclaration Ident Type
87 -- A value declaration (name, top-level binders, optional guard, value)
89 | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
91 -- A minimal mutually recursive set of value declarations
93 | BindingGroupDeclaration [(Ident, NameKind, Value)]
95 -- A foreign import declaration (type, name, optional inline Javascript, type)
97 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
99 -- A data type foreign import (name, kind)
101 | ExternDataDeclaration ProperName Kind
103 -- A fixity declaration (fixity data, operator name)
105 | FixityDeclaration Fixity String
107 -- A module import (module name, optional set of identifiers to import)
109 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
111 -- A type class declaration (name, argument, member declarations)
113 | TypeClassDeclaration ProperName [String] [Declaration]
115 -- A type instance declaration (dependencies, class name, instance type, member declarations)
117 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
118 deriving (Show, D.Data, D.Typeable)
121-- Test if a declaration is a value declaration
123isValueDecl :: Declaration -> Bool
124isValueDecl ValueDeclaration{} = True
128-- Test if a declaration is a data type or type synonym declaration
130isDataDecl :: Declaration -> Bool
131isDataDecl DataDeclaration{} = True
132isDataDecl TypeSynonymDeclaration{} = True
136-- Test if a declaration is a module import
138isImportDecl :: Declaration -> Bool
139isImportDecl ImportDeclaration{} = True
140isImportDecl _ = False
143-- Test if a declaration is a data type foreign import
145isExternDataDecl :: Declaration -> Bool
146isExternDataDecl ExternDataDeclaration{} = True
147isExternDataDecl _ = False
150-- Test if a declaration is a fixity declaration
152isFixityDecl :: Declaration -> Bool
153isFixityDecl FixityDeclaration{} = True
154isFixityDecl _ = False
157-- Test if a declaration is a foreign import
159isExternDecl :: Declaration -> Bool
160isExternDecl ExternDeclaration{} = True
161isExternDecl _ = False
164-- Test if a declaration is a type class or instance declaration
166isTypeClassDeclaration :: Declaration -> Bool
167isTypeClassDeclaration TypeClassDeclaration{} = True
168isTypeClassDeclaration TypeInstanceDeclaration{} = True
169isTypeClassDeclaration _ = 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