git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add example, update code based on @dylex's suggestion
commitd5b3d0dbdd0706cf04e233839f7b08bd609e9b9f authorPhil Freeman <paf31@cantab.net> dateFri 28 Nov 2014, 09:57 (12 years ago) parentd218599
2 files changed+17−10
examples/passing/NestedWhere.purs+10 src/Language/PureScript/Sugar/BindingGroups.hs+7−10
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)
2626import Data.Maybe (isJust, mapMaybe)
2727import Data.Monoid ((<>))
2828import Control.Applicative ((<$>), (<*>), pure)
29+import Control.Monad ((<=<))
2930
3031import qualified Data.Set as S
3132
@@ -48,18 +49,14 @@ collapseBindingGroupsModule :: [Module] -> [Module]
4849collapseBindingGroupsModule = map $ \(Module name ds exps) -> Module name (collapseBindingGroups ds) exps
4950
5051createBindingGroups :: ModuleName -> [Declaration] -> Either ErrorStack [Declaration]
51−createBindingGroups moduleName decls = do
52− (Let result _) <- createBindingGroupsForValue (Let decls (StringLiteral (error "Placeholder string literal was used in createBindingGroups.")))
53− return result
52+createBindingGroups moduleName = mapM f <=< handleDecls
5453
5554 where
56− createBindingGroupsForValue :: 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
62− go other = return other
55+ (f, _, _) = everywhereOnValuesTopDownM return handleExprs return
56+
57+ handleExprs :: Expr -> Either ErrorStack Expr
58+ handleExprs (Let ds val) = flip Let val <$> handleDecls ds
59+ handleExprs other = return other
6360
6461 -- |
6562 -- Replace all sets of mutually-recursive declarations with binding groups