haskell / haskell/error-messages

Unhelpful error message with top-level let-bindings

Open
#14 4 comments 0 reactions 0 assignees View on GitHub
status:Composing error message tool:GHC type:error-message
Dominant language
No language data
Stars
76
Forks
19
PR merge metrics
No merged PRs in 30d

Description

From https://reddit.com/r/haskell/comments/pizmp7/haskell_beginner_what_am_i_doing_wrong_i/

The code in question is:

```haskell
let triangles = [ (a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10] ]
let rightTriangles = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2 ]
```

If you save this to a file (say `Let.hs`) and compile it with `ghc`, it will produce this error message:

```
Let.hs:2:1: error:
parse error (possibly incorrect indentation or mismatched brackets)
|
2 | let rightTriangles = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2 ]
| ^
```

I think the problem is that it expects the `in ...` part of a `let ... in ...` expression which can occur at the top level if `TemplateHaskell` is enabled. Such expressions require indentation, so I think it complains about that.

It seems to me to be difficult to improve this without hard-coding a check for top-level `let` bindings. Maybe that is what we should do? Or perhaps someone can come up with a more general solution.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.