backup commit

This commit is contained in:
2022-10-24 03:16:04 +01:00
parent fbbd6ed256
commit 778c87db77
43 changed files with 1156 additions and 174 deletions

View File

@@ -1,23 +1,46 @@
-- import std::io::(println, out) -- imports
opaque := \T. T
-- single word rule (alias)
greet =1=> (\name. printf out "Hello {}!\n" [name])
-- multi-word exported rule
export ;> $a =200=> (greet $a)
reeee := \$a.b
-- single-word exported rule
export main := (
print "What is your name?" >>
readln >>= \name.
greet name
--[ Typeclass definition (also just a type) ]--
define Add $L:type $R:type $O:type as $L -> $R -> $O
-- HKTC
define Mappable $C:(type -> type) as @T. @U. (T -> U) -> $C T -> $C U
-- Dependency on existing typeclass
define Zippable $C:(type -> type) as @:Mappable $C. (
@T. @U. @V. (T -> U -> V) -> $C T -> $C U -> $C V
)
define Default $T:type as $T
-- Is the intersection of typeclasses an operation we need?
export < $a ...$rest /> := (createElement (tok_to_str $a) [(props_carriage ...$rest)])
export (props_carriage $key = $value) := (tok_to_str $key) => $value
--[ Type definition ]--
define Cons $elem:type as loop \r. Option (Pair T $elem)
nil := @T. from @(Cons T) none
cons := @T. \el:T. (
generalise @(Cons T)
|> (\list. some t[el, into list])
|> categorise @(Cons T)
)
export map := @T. @U. \f:T -> U. (
generalise @(Cons T)
|> loop ( \recurse. \option.
map option \pair. t[f (fst pair), recurse (snd pair)]
)
|> categorise @(Cons U)
)
-- Universal typeclass implementation; no parameters, no overrides, no name for overriding
impl Mappable Cons via map
-- Blanket typeclass implementation; parametric, may override, must have name for overriding
impl (@T. Add (Cons T) (Cons T) (Cons T)) by concatenation over elementwiseAddition via concat
-- The broadest trait definition in existence
Foo := (Bar Baz)
-- default anyFoo = @T. @impl:(T (Bar Baz)). impl:(T Foo)
-- Scratchpad
filterBadWords := @C:type -> type. @:Mappable C. \strings:C String. (
map strings \s. if intersects badWords (slice " " s) then none else some s
):(C (Option String))
-- /Scratchpad
main := \x. foo @bar x
foo := @util. \x. util x
export opaque := \T. atom

View File

@@ -1,18 +0,0 @@
export ::(main, foo)
main := [foo, bar, baz, quz]
foo := steamed hams
[...$data] := (cons_start ...$data cons_carriage(none))
[] := none
...$prefix:1 , ...$item cons_carriage(
$tail
) := ...$prefix cons_carriage(
(some (cons (...$item) $tail))
)
cons_start ...$item cons_carriage($tail) := some (cons (...$item) $tail)