elm-verify-examples
elm-verify-examples copied to clipboard
Error parsing if statement in example
Hi,
I am trying to incorporate elm-verify-examples and so far its going pretty good.
However I do have one example which is having a problem. Here my is my function and its documentation..
{-| The `unfoldr` function is "dual" to `foldr`. `foldr` reduces a list to a summary value, `unfoldr` builds a list from a seed. The function takes a function and a starting element. It applies the function to the element. If the result is `Just (a, b)`, `a` is accumulated and the function is applied to `b`. If the result is `Nothing`, the list accumulated so far is returned.
subtractOneUntilZero : Int -> Maybe (Int, Int)
subtractOneUntilZero i =
if i /= 0 then
Just (i, i - 1)
else
Nothing
unfoldr subtractOneUntilZero 5
--> [ 5, 4, 3, 2, 1 ]
-}
unfoldr : (b -> Maybe ( a, b )) -> b -> List a
unfoldr f seed =
case f seed of
Nothing ->
[]
Just ( a, b ) ->
a :: unfoldr f b
When I run elm-verify-example on this function I get this error..
Ct:list-extra Chadtech$ elm-verify-examples
-- PARSE ERROR - /Users/Chadtech/code/list-extra/tests/VerifyExamples/List/Extra/Unfoldr0.elm
Something went wrong while parsing an `if` expression in subtractOneUntilZero's
definition.
15| if i /= 0 then
16| Just (i, i - 1)
17|
18|
19|
20| spec0 : Test.Test
^
I was expecting:
- an `else` branch. An `if` must handle both possibilities.
- an argument, like `name` or `total`
- the end of that `if`. Maybe you forgot some code? Or maybe the body of
`subtractOneUntilZero` needs to be indented?
I can get around this error by just removing the empty line between the if and else..
if i /= 0 then
Just (i, i - 1)
else
Nothing
This also applies to case statements.