gleam-lang / suggestions

📙 A place for ideas and feedback
26 stars 2 forks source link

Adding an else block for conditional compilation. #139

Open CrowdHailer opened 3 years ago

CrowdHailer commented 3 years ago

Writing this up as it was discussed in discord. example:

if erlang {
  pub external fn length(of: List(a)) -> Int =
    "erlang" "length"
} else {
  pub fn length(of of: List(a)) -> Int {
    fold(of, 0, fn(_, count) { count + 1})
  }
}

This might be useful if gleam supports other targets, so potentially in the future but not very soon. else should be limited to only pure gleam, i.e. no calls to external as that is the only way it is guaranteed to continue working when new targets are added.