0

In this segment of code my compiler throws parse error on input for the line

tuple_up parsed_int list_of_points

and

let new_point = ((fst last_point), (snd last_point) + 1)

From previous posts on these errors they recommended checking the preceding whitespace, which I did. All the lines are correctly indented with tabs. It seems this problem has to do with things after the first "let" line?

go_up :: [String] -> [(Int, Int)]
go_up string_path list_of_points =
    let parsed_int = parse_current string_path
    tuple_up parsed_int list_of_points

tuple_up :: Int -> [String] -> [(Int, Int)]

tuple_up 0 list_of_points = list_of_points
tuple_up increment list_of_points =
    let last_point = tail list_of_points
    let new_point = ((fst last_point), (snd last_point) + 1)
    let new_list_of_points = list_of_points ++ new_point
    tuple_up (increment - 1) new_list_of_points
1
  • 4
    It should be let ... in ..., only in a do block you do not write an in Commented May 26, 2020 at 23:10

1 Answer 1

3

Outside of a do, let works a bit differently than inside. In particular:

  1. It requires an in. The correct syntax is let x = y in z
  2. It is possible to bind multiple values, but each one has to either have a corresponding in or come without a separate let

Applying these points to your code:

go_up :: [String] -> [(Int, Int)]
go_up string_path list_of_points =
    let parsed_int = parse_current string_path
    in tuple_up parsed_int list_of_points

tuple_up :: Int -> [String] -> [(Int, Int)]

tuple_up 0 list_of_points = list_of_points
tuple_up increment list_of_points =
    let last_point = tail list_of_points
        new_point = ((fst last_point), (snd last_point) + 1)
        new_list_of_points = list_of_points ++ new_point
    in tuple_up (increment - 1) new_list_of_points

After this you're going to get another error, because last_point is not a point, but a list (look at the definition of tail), which means you can't apply fst and snd to it.

And after that you're going to get yet another error, because your type signature says that list_of_points is a list of String, but then you're trying to treat its elements like tuples.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.