haskell - Is there a way to save the length of a list in a variable while doing recursion? -


let's have recursive function takes 2 lists , returns int so

fn ys (x:xs)         | --some condition = original length of (x:xs)         | otherwise = fn ys xs 

i need return original length of input list (before recursion has messed it) if condition 1 true. there way save original length?

you can recursion "worker" function (traditionally named go), allows refer original parameters , define variables:

fn ys xs' = go xs'       l = length xs'     go (x:xs)             | --some condition = l            | otherwise = go xs 

you want case go [] well.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -