All pastes #792183 Raw Edit

Jeff

public text v1 · immutable
·published 2007-11-21 05:58 UTC
rendered paste body
let fib count =                                                                                                                               
  let rec f length accum =                                                                                                                    
    if length < count then                                                                                                                    
      match accum with                                                                                                                        
          x :: y :: xs -> f (length+1) ((x+y) :: accum)                                                                                       
        | [x] -> failwith "local 'f' called but accum only has one starting element"                                                          
        | [] -> failwith "local 'f' called but accum is empty"                                                                                
    else                                                                                                                                      
      accum                                                                                                                                   
  in                                                                                                                                          
    f 2 [1; 0]                                                                                                                                
;;                                                                                                                                            
                                                                                                                                              
let main () =                                                                                                                                 
  fib 10                                                                                                                                      
;;                                                                                                                                            
                                                                                                                                              
let _ = main ()