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]