Skip to content

Commit

Permalink
Function currying (#5)
Browse files Browse the repository at this point in the history
* Currying functions quiz

* Add comment re: param pattern
  • Loading branch information
christian-byrne authored Oct 11, 2024
1 parent c8bbfb5 commit a3e7baf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ install-smlsharp
links.md
**/*temp.md
todo.md
temp*

# Logs
logs
Expand Down
20 changes: 20 additions & 0 deletions src/quiz04-to-be-merged/quiz04.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fun foo l = map real l;
foo [1,2,3];

fun foo l = foldr (fn (e, li) => e::e::li) [] l;
foo [1,2,3];

fun foo p l = foldr (fn (e, (lt, gt)) => if e <= p then (e::lt,gt) else (lt,e::gt)) ([],[]) l;
foo 3 [1,2,3,4,5];

fun cubelist li = map (fn(cur) => cur*cur*cur) li;
cubelist [1,2,3];

fun removeAll li x = foldr (fn (cur, acc) => if cur = x then acc else cur::acc) [] li;
removeAll [1,2,3,4,5,6,7,8,9,10] 5;

(* You can rearrange the order of the params like this *)
fun removeAll x li = foldr (fn (cur, acc) => if cur = x then acc else cur::acc) [] li;

(* But then the call site must be updated to reflect the new order *)
removeAll 0 [1,2,0,3,4,0,5];

0 comments on commit a3e7baf

Please sign in to comment.