Tasks (Polyglot)¶

In [ ]:
//// test

open testing
In [ ]:
open sm'_operators

task_id¶

In [ ]:
nominal task_id = string

task_name¶

In [ ]:
nominal task_name = string

manual_scheduling¶

In [ ]:
union manual_scheduling =
    | WithSuggestion
    | WithoutSuggestion

recurrency_offset¶

In [ ]:
union recurrency_offset =
    | Days : int
    | Weeks : int
    | Months : int

fixed_recurrency¶

In [ ]:
union fixed_recurrency =
    | Weekly : date_time.day_of_week
    | Monthly : date_time.day
    | Yearly : date_time.day * date_time.month

recurrency¶

In [ ]:
union recurrency =
    | Offset : recurrency_offset
    | Fixed : list fixed_recurrency

scheduling¶

In [ ]:
union scheduling =
    | Manual : manual_scheduling
    | Recurrent : recurrency

task¶

In [ ]:
type task =
    {
        id : task_id
        name : task_name
        scheduling : scheduling
    }

date¶

In [ ]:
type date =
    {
        year : date_time.year
        month : date_time.month
        day : date_time.day
    }

status¶

In [ ]:
union status =
    | Postponed : option ()

action¶

In [ ]:
union action =
    | SetDate : date
    | AddTask : task
    | SetScheduling : task * scheduling
    | AddStatus : task * date * status

get_actions (test)¶

In [ ]:
//// test

inl get_actions () : list action =
    open date_time
    [
        SetDate {
            year = year 2000
            month = February
            day = day 29
        }
        AddTask {
            id = task_id "1"
            name = task_name "1"
            scheduling = Manual WithSuggestion
        }
        AddTask {
            id = task_id "02"
            name = task_name "02"
            scheduling = Manual WithSuggestion
        }
        AddTask {
            id = task_id "003"
            name = task_name "003"
            scheduling = Manual WithSuggestion
        }
    ]
In [ ]:
//// test
///! gleam
///! fsharp
///! cuda
///! rust
///! typescript
///! python

get_actions ()
|> sm'.format_debug
|> _assert sm'.contains "003"
.py output (Python):
{ name = __assert; actual = 003; expected = UH1_1(v0=US1_0(v0=2000, v1=US0_1(), v2=29), v1=UH1_1(v0=US1_1(v0='1', v1='1', v2=US2_0(v0=US3_0())), v1=UH1_1(v0=US1_1(v0='02', v1='02', v2=US2_0(v0=US3_0())), v1=UH1_1(v0=US1_1(v0='003', v1='003', v2=US2_0(v0=US3_0())), v1=UH1_0())))) }

.rs output:
{ name = __assert; actual = 003; expected = UH1_1(US1_0(2000, US0_1, 29), UH1_1(US1_1("1", "1", US2_0(US3_0)), UH1_1(US1_1("02", "02", US2_0(US3_0)), UH1_1(US1_1("003", "003", US2_0(US3_0)), UH1_0)))) }

.ts output:
{ name = __assert; actual = 003; expected = UH1_1 (US1_0 (2000, US0_1, 29), UH1_1 (US1_1 (1, 1, US2_0 US3_0), UH1_1 (US1_1 (02, 02, US2_0 US3_0), UH1_1 (US1_1 (003, 003, US2_0 US3_0), UH1_0)))) }

.py output:
{ name = __assert; actual = 003; expected = UH1_1 (US1_0 (2000, US0_1, 29), UH1_1 (US1_1 ("1", "1", US2_0 US3_0), UH1_1 (US1_1 ("02", "02", US2_0 US3_0), UH1_1 (US1_1 ("003", "003", US2_0 US3_0), UH1_0)))) }

.gleam output (Gleam):
{ name = __assert; actual = 003; expected = Uh1i1(Us1i0(2000, Us0i1, 29), Uh1i1(Us1i1("1", "1", Us2i0(Us3i0)), Uh1i1(Us1i1("02", "02", Us2i0(Us3i0)), Uh1i1(Us1i1("003", "003", Us2i0(Us3i0)), Uh1i0)))) }

.fsx output:
{ name = __assert; actual = 003; expected = UH1_1
  (US1_0 (2000, US0_1, 29),
   UH1_1
     (US1_1 ("1", "1", US2_0 US3_0),
      UH1_1
        (US1_1 ("02", "02", US2_0 US3_0),
         UH1_1 (US1_1 ("003", "003", US2_0 US3_0), UH1_0)))) }
In [ ]:
//// test
///! gleam
///! fsharp
///! cuda
///! rust
///! typescript
///! python

get_actions ()
|> listm'.try_item 3i32
|> fun (Some action) =>
    match action with
    | AddTask { name } => name
|> _assert_eq (task_name "003")
.py output (Python):
{ name = __assert_eq; actual = 003; expected = 003 }

.rs output:
{ name = __assert_eq; actual = "003"; expected = "003" }

.ts output:
{ name = __assert_eq; actual = 003; expected = 003 }

.py output:
{ name = __assert_eq; actual = 003; expected = 003 }

.gleam output (Gleam):
{ name = __assert_eq; actual = "003"; expected = "003" }

.fsx output:
{ name = __assert_eq; actual = "003"; expected = "003" }
In [ ]:
//// test

inl print padding cols =
    ({ lines = []; last_lines = []; max_acc = 0i32 }, cols)
    ||> listm.fold fun { last_lines max_acc } lines =>
        inl { count max } =
            (lines, { count = 0i32; max = 0i32 })
            ||> listm.foldBack fun line { count max } => {
                count = count + 1
                max =
                    inl len = line |> sm'.length
                    if len > max
                    then len
                    else max
            }
        inl { lines } =
            (lines, { lines = []; i = 0i32 })
            ||> listm.foldBack fun line { lines i } => {
                lines =
                    inl last_line =
                        last_lines
                        |> listm'.try_item (count - i - 1)
                        |> optionm'.default_with fun () =>
                            " " |> sm'.replicate max_acc
                    inl line =
                        if padding = 0
                        then line
                        else
                            inl padding = " " |> sm'.replicate padding
                            line ++# padding
                    inl line = line |> sm'.pad_right (max + padding) ' '
                    last_line ++# line :: lines
                i = i + 1
            }
        {
            lines
            last_lines = lines
            max_acc = max_acc + max + padding
        }
    |> fun x => x.lines
    |> listm'.box
    |> seq.of_list'
    |> sm'.concat "\n"

inl col () =
    [ "Task" ]
    ++ (
        get_actions ()
        |> listm.map fun action =>
            match action with
            | AddTask { name } =>
                inl (task_name name) = name
                name
            | _ => ""
    )

inl cols () =
    [
        col ()
        col ()
        [ "a"; "b"; "c"; "d"; "e" ]
    ]
In [ ]:
//// test
///! gleam
///! fsharp
///! cuda
///! rust
///! typescript
///! python
///// print_code

cols ()
|> print 1i32
|> console.write_line
.py output (Python):
Task Task a 
          b 
1    1    c 
02   02   d 
003  003  e 


.rs output:
Task Task a 
          b 
1    1    c 
02   02   d 
003  003  e 


.ts output:
Task Task a 
          b 
1    1    c 
02   02   d 
003  003  e 


.py output:
Task Task a 
          b 
1    1    c 
02   02   d 
003  003  e 


.gleam output (Gleam):
Task Task a 
          b 
1    1    c 
02   02   d 
003  003  e 


.fsx output:
Task Task a 
          b 
1    1    c 
02   02   d 
003  003  e 
In [ ]:
//// test

inl task_name_width =
    (0, get_actions ())
    ||> listm.fold fun acc action =>
        match action with
        | AddTask { name } =>
            inl (task_name name) = name
            inl l = name |> sm'.length
            if l > acc
            then l
            else acc
        | _ => acc
    |> (+) 1


("" |> sm'.pad_right task_name_width ' ')
++# "|" ++# " 2000               "
++# "|"
|> console.write_line

("" |> sm'.pad_right task_name_width ' ')
++# "|" ++# " february  "
++# "|" ++# " march  "
++# "|"
|> console.write_line

("" |> sm'.pad_right task_name_width ' ')
++# "|" ++# "sa"
++# "|" ++# "su"
++# "|" ++# "mo"
++# "|" ++# "tu"
++# "|" ++# "we"
++# "|" ++# "th"
++# "|" ++# "fr"
++# "|"
|> console.write_line

("" |> sm'.pad_right task_name_width ' ')
++# "|" ++# "26"
++# "|" ++# "27"
++# "|" ++# "28"
++# "|" ++# "29"
++# "|" ++# "01"
++# "|" ++# "02"
++# "|" ++# "03"
++# "|"
|> console.write_line

inl lines =
    ("", get_actions ())
    ||> listm.fold fun acc action =>
        match action with
        | AddTask { name } =>
            inl (task_name name) = name
            if acc = ""
            then acc
            else acc ++# "\n"
            ++# (name |> sm'.pad_right task_name_width ' ')
            ++# "|" ++# console.color_bright_white () ++# "??" ++# console.color_reset ()
            ++# "|" ++# console.color_bright_white () ++# "??" ++# console.color_reset ()
            ++# "|" ++# console.color_bright_green () ++# "??" ++# console.color_reset ()
            ++# "|" ++# console.color_yellow () ++# "??" ++# console.color_reset ()
            ++# "|" ++# console.color_bright_red () ++# "??" ++# console.color_reset ()
            ++# "|" ++# console.color_bright_magenta () ++# "??" ++# console.color_reset ()
            ++# "|" ++# console.color_bright_cyan () ++# "??" ++# console.color_reset ()
            ++# "|"
        | _ => ""
lines |> console.write_line
    | 2000               |
    | february  | march  |
    |sa|su|mo|tu|we|th|fr|
    |26|27|28|29|01|02|03|
1   |??|??|??|??|??|??|??|
02  |??|??|??|??|??|??|??|
003 |??|??|??|??|??|??|??|