git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add example, update code based on @dylex's suggestion
d5b3d0dPhil Freeman
examples/passing/NestedWhere.pursnew file+10
@@ -0,0 +1,10 @@
1+module Main where
2+
3+f x = g x
4+ where
5+ g x = go x
6+ where
7+ go x = go1 (x - 1)
8+ go1 x = go x
9+
10+main = Debug.Trace.trace "Done"
src/Language/PureScript/Sugar/BindingGroups.hs+7−10
@@ -26,6 +26,7 @@ import Data.List (nub, intersect)
26import Data.Maybe (isJust, mapMaybe)
26import Data.Maybe (isJust, mapMaybe)
27import Data.Monoid ((<>))
27import Data.Monoid ((<>))
28import Control.Applicative ((<$>), (<*>), pure)
28import Control.Applicative ((<$>), (<*>), pure)
29+import Control.Monad ((<=<))
29
30
30import qualified Data.Set as S
31import qualified Data.Set as S
31
32
@@ -48,18 +49,14 @@ collapseBindingGroupsModule :: [Module] -> [Module]
48collapseBindingGroupsModule = map $ \(Module name ds exps) -> Module name (collapseBindingGroups ds) exps
49collapseBindingGroupsModule = map $ \(Module name ds exps) -> Module name (collapseBindingGroups ds) exps
49
50
50createBindingGroups :: ModuleName -> [Declaration] -> Either ErrorStack [Declaration]
51createBindingGroups :: ModuleName -> [Declaration] -> Either ErrorStack [Declaration]
51−createBindingGroups moduleName decls = do
52+createBindingGroups moduleName = mapM f <=< handleDecls
52− (Let result _) <- createBindingGroupsForValue (Let decls (StringLiteral (error "Placeholder string literal was used in createBindingGroups.")))
53− return result
54
53
55 where
54 where
55+ (f, _, _) = everywhereOnValuesTopDownM return handleExprs return
56+
56− createBindingGroupsForValue :: Expr -> Either ErrorStack Expr
57+ handleExprs :: Expr -> Either ErrorStack Expr
57− createBindingGroupsForValue =
58− let (_, f, _) = everywhereOnValuesTopDownM return go return
59− in f
60− where
61− go (Let ds val) = flip Let val <$> handleDecls ds
58+ handleExprs (Let ds val) = flip Let val <$> handleDecls ds
62− go other = return other
59+ handleExprs other = return other
63
60
64 -- |
61 -- |
65 -- Replace all sets of mutually-recursive declarations with binding groups
62 -- Replace all sets of mutually-recursive declarations with binding groups