Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocr_numbers type #407

Open
sotolf2 opened this issue Jan 22, 2024 · 1 comment
Open

ocr_numbers type #407

sotolf2 opened this issue Jan 22, 2024 · 1 comment

Comments

@sotolf2
Copy link

sotolf2 commented Jan 22, 2024

For this task the naming of the last output variant type is confusing and will easily lead to type errors in the solution

pub type Output {
  Unknown
  Digit(Int)
  List(List(Output))
}

fn ocr_line(line: List(List(String))) -> List(Output) {

  io.debug(line)
  [Unknown]
}

fn ocr(lines: List(List(String))) -> Output {
  lines
  |> list.sized_chunk(4)
  |> list.map(ocr_line)
}

But gleam isn't happy and says:

   ┌─ /home/torerling/exercism/gleam/ocr-numbers/src/ocr_numbers.gleam:24:3
   │
24 │ ╭   lines
25 │ │   |> list.sized_chunk(4)
26 │ │   |> list.map(ocr_line)
   │ ╰───────────────────────^

The type of this returned value doesn't match the return type
annotation of this function.

Expected type:

    Output

Found type:

    List(List(Output))

It makes it very easy to assume that List(List(Output)) is an output? But it's not since it's the gleam list
Maybe it would be better to have something like

pub type Output {
  Unknown
  Digit(Int)
  Digits(List(Output))
}

or the like.

@lpil
Copy link
Member

lpil commented Jan 23, 2024

Good idea, yes please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants