1module PatternMatchBench where
4 Nest Float (NestedStructure)
8intToNest : Int -> NestedStructure
17 helper (i-1) <| Nest (toFloat <| i * i) accum
19 helper i (End <| toFloat i)
21deepMatchingFunction : NestedStructure -> Float
22deepMatchingFunction struct =
24 (Nest x1 (Nest x2 (Nest x3 (Nest x4 (Nest x5 (Nest x6 (Nest x7 (Nest x8 (Nest x9 (Nest x10 (Nest x11 (Nest x12 (Nest x13 (Nest x14 (Nest x15 (Nest x16 (Nest x17 (End x18 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ->
25 x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18
34wildcardMatchingFunction : NestedStructure -> Float
35wildcardMatchingFunction struct =
37 (Nest x (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (End y ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ->
38 x + y + x + y + x + y + x + y + x + y + x + y + x + y + x + y + x + y
47shallowMatchingFunction : NestedStructure -> Float
48shallowMatchingFunction struct =
50 (Nest x1 (Nest x2 (Nest x3 (End x4) ) ) ) ->
51 x1 + x2 + x3 + x4 + x1 + x2 + x3 + x4 + x1 + x2 + x3 + x4 + x1 + x2 + x3 + x4 + x1 + x2
59sumStructures : (NestedStructure -> Float) -> List NestedStructure -> Float
60sumStructures f inList =
61 List.foldr (\x sumSoFar -> sumSoFar + f x) 0.0 inList
64deepMatchSum = sumStructures deepMatchingFunction
67shallowMatchSum = sumStructures shallowMatchingFunction
70wildcardMatchSum = sumStructures wildcardMatchingFunction
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list