From 1926a5e69ecd859a0ad01d85ef548357491f044f Mon Sep 17 00:00:00 2001 From: Ingo Wechsung Date: Thu, 10 May 2018 13:20:43 +0200 Subject: [PATCH] fix #357 --- tests/comp/Issue357.fr | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/comp/Issue357.fr diff --git a/tests/comp/Issue357.fr b/tests/comp/Issue357.fr new file mode 100644 index 00000000..f4e053f6 --- /dev/null +++ b/tests/comp/Issue357.fr @@ -0,0 +1,13 @@ +{-- + As outlined in 'https://github.com/Frege/frege/issues/357 #357', + the compiler decides that 'myFoldM' should be strict, despite the tail call + 'Maybe.>>=' returns lazy. This is unfortunate, because the recursion happens + on the stack, instead through a Thunk returned by >>= +-} +module tests.comp.Issue357 where + +myFoldM :: (b -> a -> Maybe b) -> b -> [a] -> Maybe b +myFoldM f z (x:xs) = f z x >>= \acc -> myFoldM f acc xs +myFoldM _ z [] = pure z + +main = println $ myFoldM (\r _ -> Just $! succ r) 0 [1..5000]