added exmaple program
This commit is contained in:
		
							
								
								
									
										51
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,3 +1,52 @@ | ||||
| # fudge2 | ||||
|  | ||||
| second iteration of the fudge language | ||||
| second iteration of the fudge language | ||||
|  | ||||
| ## example program | ||||
| ```asm | ||||
|  | ||||
| // Map, Filter, Reduce | ||||
| sig map := (T => U) => #iterable(T) => #iterable(U)  | ||||
| let map f ls := match ls | (x:xs) => (f x: map f xs) | ||||
|                          | [] => []      | ||||
|  | ||||
| // Side Effects are ugly, C-FFI | ||||
| sig polluting map := #polluting (Maybe T => U) => Iterable(T) => Nothing | ||||
| let polluting map f [ls] := | ||||
|     using std/c-ffi/guarantee_no_parallel_map as seqmap | ||||
| { | ||||
|     seqmap 0 (len ls) (i => f (ls at i)) | ||||
| } | ||||
|  | ||||
| // type traits | ||||
| sig polluting print := #repr T => Result (Nothing, #error io_error) | ||||
| let polluting print s := using std/io/write, std/io/stdout { | ||||
|     write stdout (Repr s) | ||||
| } | ||||
|  | ||||
| // Overloading? | ||||
| sig polluting print := Iterable (#repr T) => Result (Nothing, #error io_error) | ||||
| let polluting print #repr ls := using std\io as io { | ||||
|     map print ls | ||||
| } | ||||
|  | ||||
| // Generic types | ||||
| sig add := T => T => T | ||||
| let add a b := a + b | ||||
|  | ||||
| // Partial application | ||||
| sig inc := T => T | ||||
| let inc a = add a 1 | ||||
|  | ||||
| // Evaluate a polluting expression | ||||
| sig polluting do := #polluting T => Nothing | ||||
|  | ||||
| @data := struct ( | ||||
|     let arr := Array(0..100) :> inc, | ||||
|     let ls := List(0..100) :> (x=>x*x), | ||||
|     let all := arr ++ ls, | ||||
| ) | ||||
| @main := do print @data/all; | ||||
| ] | ||||
|  | ||||
| ``` | ||||
		Reference in New Issue
	
	Block a user