0 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

Full name: Script.drop
Multiple items
val list : 'a list

--------------------
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
val num : int
val dropInner : ('b list -> int -> int -> 'b list)
Multiple items
val list : 'b list

--------------------
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
val i : int
val h : 'b
val t : 'b list
val failwith : message:string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
Raw view New version

More information

Link:http://fssnip.net/rm
Posted:2 years ago
Author:Vladimir Khorikov
Tags: f# , ocaml