Re:Ask HN: Functional Programming Differences
by DanielBMarkham on Sunday March 07, 2010 @04:56PM
(#1174085)
That works. Thanks for the tip -- I never thought of foldl as a universal replacement for for/next.
Here's what I've been using for slicing:
let slice l b e =
let rec slice_2 l b e f =
match l with
[] -> f
| h::t -> if (b<2)
then
if (e>0)
then ( slice_2 t b (e-1) (f@[h]) )
else f
else
( slice_2 t (b-1) (e-1) f )
in
slice_2 l b e [];;
Re:Ask HN: Functional Programming Differences
by eru on Monday March 08, 2010 @05:17AM
(#1175080)
Though you are right that foldl and friends don't always help you. Especially in strict languages. But you can define your own combinators---to hide away the recursion in.
Here's what I've been using for slicing: