Skip to content

ocr_numbers type #407

Open
Open
@sotolf2

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions