git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add mkFn and runFn for arities up to 10 #486
commitc817be12845e52f43caac4bc0388505fed5f92d3 authorPhil Freeman <paf31@cantab.net> dateWed 16 Jul 2014, 16:40 (12 years ago) parent8b357ff
3 files changed+153−3
examples/passing/MultiArgFunctions.purs+6−1 prelude/prelude.purs+145 src/Language/PureScript/Optimizer/Inliner.hs+2−2
examples/passing/MultiArgFunctions.purs+6−1
@@ -11,4 +11,9 @@ main = do
1111 runFn3 (mkFn3 $ \a b c -> trace $ show [a, b, c]) 1 2 3
1212 runFn4 (mkFn4 $ \a b c d -> trace $ show [a, b, c, d]) 1 2 3 4
1313 runFn5 (mkFn5 $ \a b c d e -> trace $ show [a, b, c, d, e]) 1 2 3 4 5
14− trace "Done!"
14+ runFn6 (mkFn6 $ \a b c d e f -> trace $ show [a, b, c, d, e, f]) 1 2 3 4 5 6
15+ runFn7 (mkFn7 $ \a b c d e f g -> trace $ show [a, b, c, d, e, f, g]) 1 2 3 4 5 6 7
16+ runFn8 (mkFn8 $ \a b c d e f g h -> trace $ show [a, b, c, d, e, f, g, h]) 1 2 3 4 5 6 7 8
17+ runFn9 (mkFn9 $ \a b c d e f g h i -> trace $ show [a, b, c, d, e, f, g, h, i]) 1 2 3 4 5 6 7 8 9
18+ runFn10 (mkFn10 $ \a b c d e f g h i j-> trace $ show [a, b, c, d, e, f, g, h, i, j]) 1 2 3 4 5 6 7 8 9 10
19+ trace "Done!"
prelude/prelude.purs+145
@@ -490,6 +490,11 @@ module Data.Function where
490490 foreign import data Fn3 :: * -> * -> * -> * -> *
491491 foreign import data Fn4 :: * -> * -> * -> * -> * -> *
492492 foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
493+ foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
494+ foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
495+ foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
496+ foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
497+ foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
493498
494499 foreign import mkFn0
495500 "function mkFn0(f) {\
@@ -533,6 +538,41 @@ module Data.Function where
533538 \ };\
534539 \}" :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
535540
541+ foreign import mkFn6
542+ "function mkFn6(f) {\
543+ \ return function(a, b, c, d, e, f) {\
544+ \ return f(a)(b)(c)(d)(e)(f);\
545+ \ };\
546+ \}" :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
547+
548+ foreign import mkFn7
549+ "function mkFn7(f) {\
550+ \ return function(a, b, c, d, e, f, g) {\
551+ \ return f(a)(b)(c)(d)(e)(f)(g);\
552+ \ };\
553+ \}" :: forall a b c d e f g h. (a -> b -> c -> d -> e -> f -> g -> h) -> Fn7 a b c d e f g h
554+
555+ foreign import mkFn8
556+ "function mkFn8(f) {\
557+ \ return function(a, b, c, d, e, f, g, h) {\
558+ \ return f(a)(b)(c)(d)(e)(f)(g)(h);\
559+ \ };\
560+ \}" :: forall a b c d e f g h i. (a -> b -> c -> d -> e -> f -> g -> h -> i) -> Fn8 a b c d e f g h i
561+
562+ foreign import mkFn9
563+ "function mkFn9(f) {\
564+ \ return function(a, b, c, d, e, f, g, h, i) {\
565+ \ return f(a)(b)(c)(d)(e)(f)(g)(h)(i);\
566+ \ };\
567+ \}" :: forall a b c d e f g h i j. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j) -> Fn9 a b c d e f g h i j
568+
569+ foreign import mkFn10
570+ "function mkFn10(f) {\
571+ \ return function(a, b, c, d, e, f, g, h, i, j) {\
572+ \ return f(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);\
573+ \ };\
574+ \}" :: forall a b c d e f g h i j k. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k) -> Fn10 a b c d e f g h i j k
575+
536576 foreign import runFn0
537577 "function runFn0(f) {\
538578 \ return f();\
@@ -593,6 +633,111 @@ module Data.Function where
593633 \ };\
594634 \}" :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
595635
636+ foreign import runFn6
637+ "function runFn6(f) {\
638+ \ return function(a) {\
639+ \ return function(b) {\
640+ \ return function(c) {\
641+ \ return function(d) {\
642+ \ return function(e) {\
643+ \ return function(f) {\
644+ \ return f(a, b, c, d, e, f);\
645+ \ };\
646+ \ };\
647+ \ };\
648+ \ };\
649+ \ };\
650+ \ };\
651+ \}" :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
652+
653+ foreign import runFn7
654+ "function runFn7(f) {\
655+ \ return function(a) {\
656+ \ return function(b) {\
657+ \ return function(c) {\
658+ \ return function(d) {\
659+ \ return function(e) {\
660+ \ return function(f) {\
661+ \ return function(g) {\
662+ \ return f(a, b, c, d, e, f, g);\
663+ \ };\
664+ \ };\
665+ \ };\
666+ \ };\
667+ \ };\
668+ \ };\
669+ \ };\
670+ \}" :: forall a b c d e f g h. Fn7 a b c d e f g h -> a -> b -> c -> d -> e -> f -> g -> h
671+
672+ foreign import runFn8
673+ "function runFn8(f) {\
674+ \ return function(a) {\
675+ \ return function(b) {\
676+ \ return function(c) {\
677+ \ return function(d) {\
678+ \ return function(e) {\
679+ \ return function(f) {\
680+ \ return function(g) {\
681+ \ return function(h) {\
682+ \ return f(a, b, c, d, e, f, g, h);\
683+ \ };\
684+ \ };\
685+ \ };\
686+ \ };\
687+ \ };\
688+ \ };\
689+ \ };\
690+ \ };\
691+ \}" :: forall a b c d e f g h i. Fn8 a b c d e f g h i -> a -> b -> c -> d -> e -> f -> g -> h -> i
692+
693+ foreign import runFn9
694+ "function runFn9(f) {\
695+ \ return function(a) {\
696+ \ return function(b) {\
697+ \ return function(c) {\
698+ \ return function(d) {\
699+ \ return function(e) {\
700+ \ return function(f) {\
701+ \ return function(g) {\
702+ \ return function(h) {\
703+ \ return function(i) {\
704+ \ return f(a, b, c, d, e, f, g, h, i);\
705+ \ };\
706+ \ };\
707+ \ };\
708+ \ };\
709+ \ };\
710+ \ };\
711+ \ };\
712+ \ };\
713+ \ };\
714+ \}" :: forall a b c d e f g h i j. Fn9 a b c d e f g h i j -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j
715+
716+ foreign import runFn10
717+ "function runFn10(f) {\
718+ \ return function(a) {\
719+ \ return function(b) {\
720+ \ return function(c) {\
721+ \ return function(d) {\
722+ \ return function(e) {\
723+ \ return function(f) {\
724+ \ return function(g) {\
725+ \ return function(h) {\
726+ \ return function(i) {\
727+ \ return function(j) {\
728+ \ return f(a, b, c, d, e, f, g, h, i, j);\
729+ \ };\
730+ \ };\
731+ \ };\
732+ \ };\
733+ \ };\
734+ \ };\
735+ \ };\
736+ \ };\
737+ \ };\
738+ \ };\
739+ \}" :: forall a b c d e f g h i j k. Fn10 a b c d e f g h i j k -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k
740+
596741module Data.Eq where
597742
598743 data Ref a = Ref a
src/Language/PureScript/Optimizer/Inliner.hs+2−2
@@ -124,7 +124,7 @@ inlineCommonOperators = applyAll $
124124 , binary C.boolLikeBoolean (C.||) Or
125125 , unary C.boolLikeBoolean C.not Not
126126 ] ++
127− [ fn | i <- [0..5], fn <- [ mkFn i, runFn i ] ]
127+ [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
128128 where
129129 binary :: String -> String -> BinaryOperator -> JS -> JS
130130 binary dictName opString op = everywhereOnJS convert
@@ -170,7 +170,7 @@ inlineCommonOperators = applyAll $
170170 Nothing -> orig
171171 convert other = other
172172 collectArgs :: Int -> [String] -> JS -> Maybe ([String], [JS])
173− collectArgs 1 acc (JSFunction Nothing [oneArg] (JSBlock js)) | length acc == n - 1 = Just (reverse (oneArg : acc), js)
173+ collectArgs 1 acc (JSFunction Nothing [oneArg] (JSBlock js)) | length acc == n - 1 = Just (reverse (oneArg : acc), js)
174174 collectArgs m acc (JSFunction Nothing [oneArg] (JSBlock [JSReturn ret])) = collectArgs (m - 1) (oneArg : acc) ret
175175 collectArgs _ _ _ = Nothing
176176