1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.BindingGroups
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15module Language.PureScript.BindingGroups (
17 createBindingGroupsModule
21import Data.List (intersect)
23import Language.PureScript.Declarations
24import Language.PureScript.Names
25import Language.PureScript.Values
26import Language.PureScript.Scope (usedNames)
28createBindingGroupsModule :: [Module] -> [Module]
29createBindingGroupsModule = map $ \(Module name ds) -> Module name (createBindingGroups ds)
31createBindingGroups :: [Declaration] -> [Declaration]
32createBindingGroups ds =
34 values = filter isValueDecl ds
35 nonValues = filter (not . isValueDecl) ds
36 allIdents = map getIdent values
37 verts = map (\d -> (d, getIdent d, usedNames d `intersect` allIdents)) values
38 sorted = map toBindingGroup $ stronglyConnComp verts
42isValueDecl :: Declaration -> Bool
43isValueDecl (ValueDeclaration _ _ _ _) = True
46getIdent :: Declaration -> Ident
47getIdent (ValueDeclaration ident _ _ _) = ident
48getIdent _ = error "Expected ValueDeclaration"
50toBindingGroup :: SCC Declaration -> Declaration
51toBindingGroup (AcyclicSCC d) = d
52toBindingGroup (CyclicSCC [d]) = d
53toBindingGroup (CyclicSCC ds') = BindingGroupDeclaration (map fromValueDecl ds')
55fromValueDecl :: Declaration -> (Ident, Value)
56fromValueDecl (ValueDeclaration ident [] Nothing val) = (ident, val)
57fromValueDecl (ValueDeclaration _ _ _ _) = error "Binders should have been desugared"
58fromValueDecl _ = error "Expected ValueDeclaration"
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