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
day_offset¶
In [ ]:
nominal day_offset = int
week_offset¶
In [ ]:
nominal week_offset = int
month_offset¶
In [ ]:
nominal month_offset = int
recurrency_offset¶
In [ ]:
union recurrency_offset =
    | Days : day_offset
    | Weeks : week_offset
    | Months : month_offset
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 "00003"
            name = task_name "00003"
            scheduling = Manual WithSuggestion
        }
    ]
In [ ]:
//// test
///! gleam
///! fsharp
///! cuda
///! rust
///! typescript
///! python
get_actions ()
|> sm'.format_debug
|> _assert sm'.contains "00003"
.py output (Python):
{ name = __assert; 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='00003', v1='00003', v2=US2_0(v0=US3_0())), v1=UH1_0())))) }
.rs output:
{ name = __assert; 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("00003", "00003", US2_0(US3_0)), UH1_0)))) }
.ts output:
{ name = __assert; 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 (00003, 00003, US2_0 US3_0), UH1_0)))) }
.py output:
{ name = __assert; 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 ("00003", "00003", US2_0 US3_0), UH1_0)))) }
.gleam output (Gleam):
{ name = __assert; expected = Uh1i1(Us1i0(2000, Us0i1, 29), Uh1i1(Us1i1("1", "1", Us2i0(Us3i0)), Uh1i1(Us1i1("02", "02", Us2i0(Us3i0)), Uh1i1(Us1i1("00003", "00003", Us2i0(Us3i0)), Uh1i0)))) }
.fsx output:
{ name = __assert; 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 ("00003", "00003", US2_0 US3_0), UH1_0)))) }
In [ ]:
//// test
///! gleam
///! fsharp
///! cuda
///! rust
///! typescript
///! python
get_actions ()
|> listm'.try_item 3i32
|> function
    | Some (AddTask { name }) => name
|> _assert_eq (task_name "00003")
.py output (Python):
{ name = __assert_eq; expected = 00003 }
.rs output:
{ name = __assert_eq; expected = "00003" }
.ts output:
{ name = __assert_eq; expected = 00003 }
.py output:
{ name = __assert_eq; expected = 00003 }
.gleam output (Gleam):
{ name = __assert_eq; expected = "00003" }
.fsx output:
{ name = __assert_eq; expected = "00003" }
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 function
            | 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 
00003 00003 e
.rs output:
Task  Task  a 
            b 
1     1     c 
02    02    d 
00003 00003 e
.ts output:
Task  Task  a 
            b 
1     1     c 
02    02    d 
00003 00003 e
.py output:
Task  Task  a 
            b 
1     1     c 
02    02    d 
00003 00003 e
.gleam output (Gleam):
Task  Task  a 
            b 
1     1     c 
02    02    d 
00003 00003 e
.fsx output:
Task  Task  a 
            b 
1     1     c 
02    02    d 
00003 00003 e 
In [ ]:
//// test
inl task_name_width =
    (0, get_actions ())
    ||> listm.fold fun acc => function
        | AddTask { name } =>
            inl (task_name name) = name
            inl l = name |> sm'.length
            if l > acc
            then l
            else acc
        | _ => acc
    |> (+) 1
inl lines =
    ("" |> sm'.pad_right task_name_width ' ')
    ++# "|" ++# " 2000               "
    ++# "|\n"
    ++# ("" |> sm'.pad_right task_name_width ' ')
    ++# "|" ++# " february  "
    ++# "|" ++# " march  "
    ++# "|\n"
    ++# ("" |> sm'.pad_right task_name_width ' ')
    ++# "|" ++# "sa"
    ++# "|" ++# "su"
    ++# "|" ++# "mo"
    ++# "|" ++# "tu"
    ++# "|" ++# "we"
    ++# "|" ++# "th"
    ++# "|" ++# "fr"
    ++# "|\n"
    ++# ("" |> sm'.pad_right task_name_width ' ')
    ++# "|" ++# "26"
    ++# "|" ++# "27"
    ++# "|" ++# "28"
    ++# "|" ++# "29"
    ++# "|" ++# "01"
    ++# "|" ++# "02"
    ++# "|" ++# "03"
    ++# "|"
inl lines =
    (lines, get_actions ())
    ||> listm.fold fun acc => function
        | 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 ()
            ++# "|"
        | _ => acc
lines
      | 2000               |
      | february  | march  |
      |sa|su|mo|tu|we|th|fr|
      |26|27|28|29|01|02|03|
1     |??|??|??|??|??|??|??|
02    |??|??|??|??|??|??|??|
00003 |??|??|??|??|??|??|??|