Difference between revisions of "Curried Higher Order Function Debugging"

From CSE425S Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=Code To Debug=
 
=Code To Debug=
{{SMLToDebug|fix_me_hof_hof_a|group_curry_hof_debug}}
+
==A==
 +
{{SMLToDebug|a_fix_me_hof_hof|group_curry_hof_debug}}
  
{{SMLToImplement|fix_me_hof_hof_b|---debug-file---|group_curry_hof_debug}}
+
<syntaxhighlight lang="sml">
 +
fun add(a,b) =
 +
    a + b
 +
val sum = foldl(add, 0, [1,2,3,4])
 +
</syntaxhighlight>
  
{{SMLToImplement|fix_me_hof_hof_c|---debug-file---|group_curry_hof_debug}}
+
==B==
 +
{{SMLToDebug|b_fix_me_hof_hof|group_curry_hof_debug}}
  
{{SMLToImplement|fix_me_hof_hof_d|---debug-file---|group_curry_hof_debug}}
+
<syntaxhighlight lang="sml">
 +
val sum = foldl(op+, 0, [1,2,3,4])
 +
</syntaxhighlight>
  
{{SMLToImplement|fix_me_hof_hof_e|---debug-file---|group_curry_hof_debug}}
+
==C==
 +
{{SMLToDebug|c_fix_me_hof_hof|group_curry_hof_debug}}
  
{{SMLToImplement|fix_me_hof_hof_f|---debug-file---|group_curry_hof_debug}}
+
<syntaxhighlight lang="sml">
 +
fun range(min, maxExclusive) =
 +
    if min>=maxExclusive
 +
    then []
 +
    else min::range(min+1, maxExclusive)
 +
 
 +
val xs = range(1, 5)
 +
val sum_a = foldl op+ 0 xs
 +
val sum_b = foldl op+ 0 range(1, 5)
 +
</syntaxhighlight>
 +
 
 +
==D==
 +
{{SMLToDebug|d_fix_me_hof_hof|group_curry_hof_debug}}
 +
 
 +
<syntaxhighlight lang="sml">
 +
fun to_x(x, _) =
 +
    x
 +
 
 +
val xys = [(10,20), (30,40), (50, 60)]
 +
 
 +
val xs = map xys to_x
 +
 
 +
val sum_xs = foldl op+ 0 xs
 +
</syntaxhighlight>
 +
 
 +
==E==
 +
{{SMLToDebug|e_fix_me_hof_hof|group_curry_hof_debug}}
 +
 
 +
<syntaxhighlight lang="sml">
 +
val xys = [(10,20), (30,40), (50, 60)]
 +
 
 +
val xs = map xys #1
 +
 
 +
val sum_xs = foldl op+ 0 xs
 +
</syntaxhighlight>
 +
 
 +
==F==
 +
{{SMLToDebug|f_fix_me_hof_hof|group_curry_hof_debug}}
 +
 
 +
<syntaxhighlight lang="sml">
 +
val map_function = map
 +
val filter_function_requires_list_module = filter (* requires List.filter *)
 +
val fold_left_function = foldl
 +
val fold_right_function = foldr
 +
val find_function_requires_list_module = find (* requires List.find *)
 +
 
 +
 
 +
val list_map_function_also_works = List.map
 +
val list_foldl_function_also_works = List.foldl
 +
val list_foldr_function_also_works = List.foldr
 +
</syntaxhighlight>
  
 
=Code To Implement=
 
=Code To Implement=
 
{{SMLToImplement|starts_with_h|starts_with_h|group_curry_hof_debug}}
 
{{SMLToImplement|starts_with_h|starts_with_h|group_curry_hof_debug}}

Latest revision as of 01:34, 19 September 2024

Code To Debug

A

file: src/main/sml/group_curry_hof_debug/a_fix_me_hof_hof.sml Smlnj-logo.png
fun add(a,b) =
    a + b
val sum = foldl(add, 0, [1,2,3,4])

B

file: src/main/sml/group_curry_hof_debug/b_fix_me_hof_hof.sml Smlnj-logo.png
val sum = foldl(op+, 0, [1,2,3,4])

C

file: src/main/sml/group_curry_hof_debug/c_fix_me_hof_hof.sml Smlnj-logo.png
fun range(min, maxExclusive) =
    if min>=maxExclusive
    then []
    else min::range(min+1, maxExclusive)

val xs = range(1, 5)
val sum_a = foldl op+ 0 xs
val sum_b = foldl op+ 0 range(1, 5)

D

file: src/main/sml/group_curry_hof_debug/d_fix_me_hof_hof.sml Smlnj-logo.png
fun to_x(x, _) =
    x

val xys = [(10,20), (30,40), (50, 60)]

val xs = map xys to_x

val sum_xs = foldl op+ 0 xs

E

file: src/main/sml/group_curry_hof_debug/e_fix_me_hof_hof.sml Smlnj-logo.png
val xys = [(10,20), (30,40), (50, 60)]

val xs = map xys #1

val sum_xs = foldl op+ 0 xs

F

file: src/main/sml/group_curry_hof_debug/f_fix_me_hof_hof.sml Smlnj-logo.png
val map_function = map
val filter_function_requires_list_module = filter (* requires List.filter *)
val fold_left_function = foldl
val fold_right_function = foldr
val find_function_requires_list_module = find (* requires List.find *)


val list_map_function_also_works = List.map
val list_foldl_function_also_works = List.foldl
val list_foldr_function_also_works = List.foldr

Code To Implement

file: src/main/sml/group_curry_hof_debug/starts_with_h.sml Smlnj-logo.png
functions: starts_with_h