josh-degraw / gleam

Gleam.NET ⭐️ Fork of the Gleam compiler to run on .NET via F#
https://gleam.run
Apache License 2.0
17 stars 0 forks source link

BitArrays #7

Open josh-degraw opened 5 days ago

RNGKing commented 5 days ago

I don't believe in "safe" dotnet you can access things on a bit by bit basis, the smallest unit is the byte.

Sample Gleam

pub fn main() {
  io.println("Hello from hello_world!")
  let bits = <<3:size(8)>>
  case bits {
    <<head, tail>> -> {
      io.println("have some bits")
      io.debug(head)
      io.debug(tail)
    }
    _ -> {
      io.println("everything else")
      0
    }
  }
}

Output Javascript

export function main() {
  $io.println("Hello from hello_world!");
  let bits = toBitArray([sizedInt(3, 8, true)]);
  if (bits.length == 2) {
    let head = bits.byteAt(0);
    let tail = bits.byteAt(1);
    $io.println("have some bits");
    $io.debug(head);
    return $io.debug(tail);
  } else {
    $io.println("everything else");
    return 0;
  }
}

So the equivalent F# should look something like the JS imo.