Last active
September 17, 2022 09:50
-
-
Save soderstroff/3f282b248634a3054819 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- This is a comment. It is not code. There are no multi-line comments. | |
| -- You did not want those, anyway. | |
| -- Functions take arguments separated by whitespace. | |
| f x y z | |
| -- The only exception is functions of no arguments. | |
| no_args_fun ~ -- This is sort of like passing void to a function. | |
| -- Function declarations separate arguments by comma. | |
| f :: i32, i32 -> i32 | |
| f x y = x + y -- Just like Haskell! Are we functional yet? | |
| -- Functions of no arguments once again take void. | |
| no_args_allowed :: ~ -> f32 | |
| no_args_allowed ~ = 0.0f | |
| -- Finally, borrows are the exact same syntax. | |
| krevitch :: &i32, &mut i32 -> () -- Unit is different from void! | |
| krevitch snork flads = *flads = *krevitch + *flads -- The leftmost = is different from the rightmost. Or is it? | |
| -- Imports. | |
| use .std.fmt.Display -- Just like SML! | |
| -- Top level declarations work for data as well. | |
| PI :: const f64 | |
| PI = 3.14159265358979323846 | |
| web_scale_user_database :: static HashMap String String | |
| web_scale_user_database = lazy_static!(HashMap.new ~) | |
| -- Generic functions are painful...ly aesthetic! | |
| id :: A -> A forall A | |
| id a = a | |
| -- Bounds are predictable. | |
| copy :: &A -> A forall A :: Copy | |
| copy a = *a -- These function definitions probably make no sense. | |
| -- The signature could have also been written as... | |
| copy :: &A -> A forall A | |
| where A :: Copy -- where clauses are a direct port from Rust. | |
| -- Generic data is separated by spaces, not brackets. After all, isn't a generic | |
| -- datatype a function from one concrete type to another? | |
| push :: &mut Vec A, A -> () forall A | |
| -- Here's a big ol' function with everything in it. | |
| map :: F, &Vec A -> Vec B forall A, B, F | |
| where A :: Copy, F :: Fn A -> B | |
| -- We have structs! | |
| struct Point { x :: i32, y :: i32 } -- This is the only place you will ever see braces. | |
| -- Newtypes over tuples work: | |
| struct Pair(A, B) forall A, B | |
| -- Liftimes also work just as they do in Rust | |
| struct CallMeMaybe 'a { number :: &'a Girl } | |
| -- How do we define generic data, anyway? Oh, like this! | |
| enum Option A forall A = Some A | None | |
| -- Does that scale? | |
| enum Result T E forall T E where E :: Error | |
| = Ok T | Err E | |
| -- Structs get impls, too, should they so desire. | |
| impl Option A forall A | |
| map :: &self, F -> Option B forall B, F where F :: Fn A -> B | |
| map self f = -- Notice the &self argument. | |
| and_then :: &self, F -> Option B forall B, F where F :: Fn A -> Option B | |
| and_then self f = -- I'm a monad! Hear me bind! | |
| -- Bounded polymorphism. | |
| trait Typeclass :: Sized | |
| type AssocType = DefaultConcreteType -- Associated types are my favorite feature. | |
| duck_type :: &self -> String -- I am really just writing ridiculous things. | |
| unsafe_coerce :: &self -> T forall T :: From &Self | |
| unsafe_coerce self = use_magic_on self -- Default implementation. | |
| -- I can't believe I've gone this far without actually using impls! | |
| -- Impls create namespaces, so method syntax just reaches in and grabs a function from the type. | |
| terrorize_with ralf building = ralf.wreck_it building -- Is the same as... | |
| terrorize_with ralf building = Ralf.wreck_it &ralf building -- So long as wreck_it :: &self, Building -> () | |
| -- Closure? I hardly know her! (Not my joke.) | |
| let f = \x, y -> mappend x y -- I forgot to mention that let creates bindings. | |
| let g = \move x, y -> f x y -- Move must come immediately after the backslash. | |
| -- safe. | |
| let pointer = open_hell ~ | |
| -- unsafe. | |
| let mut demons = unsafe| *pointer | -- Unsafe behavior must be walled. | |
| -- You can pattern match. | |
| match x | |
| 0...2 => f x | |
| _ => panic!("{}", 0, 2) -- Hey, I can't change how macros are defined. This | |
| -- is probably for the best anyway. | |
| -- For loops require a level of identation. | |
| for c in "C'mon Tars" | |
| let u = c.to_upper_case | |
| lines.push u | |
| -- I think the only features left are patterns and slices. Those are verbatim equivalent to Rust. | |
| let (a, b) = ("Mom", "Dad") | |
| let bc@(b, c) = ("Craig", "Norman") | |
| let xs = &(bc.0)[..] | |
| let map = [Point { x: 0, y: 0 }, 20000] | |
| -- I guess I can bikeshed over compiler directives, too. | |
| #![allow(new_syntax)] -- Suprise! I really like Rust's syntax here. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment