Sha256: 364b874c8529d0aefbe0e8cfdf983bbda4811dd891333be2e1f3c9599c957578

Contents?: true

Size: 673 Bytes

Versions: 463

Compression:

Stored size: 673 Bytes

Contents

module SimpleLinkedList

type LinkedList<'a> = 
    | Nil 
    | Element of datum:'a * next:LinkedList<'a>

let nil = Nil

let create x n = Element (x, n)

let isNil x = 
    match x with
    | Nil -> true
    | _   -> false

let next x = 
    match x with
    | Nil -> Nil
    | Element (_, n) -> n

let datum x = 
    match x with
    | Nil -> failwith "The nil list has no datum."
    | Element (y, _) -> y

let toList x = 
    let rec loop acc item = 
        match item with
        | Nil -> acc |> List.rev
        | Element (b, n) -> loop (b :: acc) n

    loop [] x

let fromList xs = List.foldBack create xs Nil

let reverse x = x |> toList |> List.rev |> fromList

Version data entries

463 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/simple-linked-list/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/simple-linked-list/Example.fs