compiler-errorsgleam

Gleam unexpected struct


I'm 100% new to Gleam and tried a simple struct example I found.

// src/first.gleam

pub struct Cat {
  name: String
  is_cute: Bool
}

pub fn main() {
  Cat(name: "Nubi", is_cute: True)
}

However, I get a compile error:

% gleam run
error: Syntax error
  ┌─ C:\Users\Sven\programming\Gleam\first\src\first.gleam:3:1
  │
3 │ pub struct Cat {
  │ ^^^ I was not expecting this

Expected one of:
An import, const, type, if block, or function.

What is the solution to this?

Version output: % gleam --version gleam 1.0.0


Solution

  • Seems that the compiler gives a hint: Expected one of: An import, const, type, if block, or function..

    pub type Cat {
      Cat(name: String, is_cute: Bool)
    }