fork download
  1. let hoge n = n mod 2 = 1
  2. let piyo = ( * ) 2
  3. let () = print_int (List.fold_left (+) 0 (List.map piyo (List.filter hoge [1;2;3;4;5])))
  4.  
  5. (* function composition *)
  6. let (<<) f g x = f (g x)
  7. let f = print_int << List.fold_left (+) 0 << List.map piyo << List.filter hoge
  8. let () = f [1;2;3;4;5]
  9. let () = (print_int << List.fold_left (+) 0 << List.map piyo << List.filter hoge) [1;2;3;4;5]
  10.  
  11. let (>>) f g x = g (f x)
  12. let f = List.filter hoge >> List.map piyo >> List.fold_left (+) 0 >> print_int
  13. let () = f [1;2;3;4;5]
  14. let () = (List.filter hoge >> List.map piyo >> List.fold_left (+) 0 >> print_int) [1;2;3;4;5]
  15.  
  16.  
  17. (* @@ Application operator *)
  18. let () = print_int @@ List.fold_left (+) 0 @@ List.map piyo @@ List.filter hoge [1;2;3;4;5]
  19.  
  20. (* |> Reverse-application operator *)
  21. let () = [1;2;3;4;5] |> List.filter hoge |> List.map piyo |> List.fold_left (+) 0 |> print_int
  22.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
18181818181818