plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


plum-std/Bool.plum
5f5d99d 1
module std
b7071c9 2
import std/Result
b7071c9 3
import std/Str
5f5d99d 4
fd085d9 5
enum Bool =
5f5d99d 6
  | True
5f5d99d 7
  | False
5f5d99d 8
0fe3528 9
  fun parse(v: Str) -> Result[Bool, Str] =
3971d41 10
    if v == "true"
3971d41 11
      Ok(True)
3971d41 12
    else if v == "false"
3971d41 13
      Ok(False)
3971d41 14
    else
3971d41 15
      Err("could not parse bool from '{v}'")
e9b4405 16
0fe3528 17
  fun and(self, o: Bool) -> Bool =
3971d41 18
    match self, o
a271f34 19
      True, True => True
a271f34 20
      True, False => False
a271f34 21
      False, True => False
a271f34 22
      False, False => False
e9b4405 23
0fe3528 24
  fun or(self, o: Bool) -> Bool =
3971d41 25
    match self, o
a271f34 26
      True, True => True
a271f34 27
      True, False => True
a271f34 28
      False, True => True
a271f34 29
      False, False => False
e9b4405 30
0fe3528 31
  fun toStr(self) -> Str =
3971d41 32
    match self
a271f34 33
      True => "True"
a271f34 34
      False => "False"