7 people like it.

Drop every N'th element from a list

One of the 99 OCaml problems rewritten in F#

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
let drop list num = 
    let rec dropInner list num i = 
        match list with
        | [] -> []
        | h :: t when i < num -> h :: dropInner t num (i + 1)
        | _ :: t when i = num -> dropInner t num 1
        | _ -> failwith "error"
    dropInner list num 1
val drop : list:'a list -> num:int -> 'a list
Multiple items
val list : 'a list

--------------------
type 'T list = List<'T>
val num : int
val dropInner : ('b list -> int -> int -> 'b list)
Multiple items
val list : 'b list

--------------------
type 'T list = List<'T>
val i : int
val h : 'b
val t : 'b list
val failwith : message:string -> 'T

More information

Link:http://fssnip.net/rm
Posted:1 year ago
Author:Vladimir Khorikov
Tags: ocaml