3 people like it.
Like the snippet!
Matrix
Matrix
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
|
(* Transposes rectangular matrices *)
let transpose matrix =
let rec fetch_column acc (matr:(int list list)) = (* Makes a column list from a row list *)
if matr.Head.Length = 0 then (List.rev acc) (* Stop *)
else fetch_column
([for row in matr -> row.Head]::acc) (* Fetches the first item from each row *)
(List.map (fun row -> match row with [] -> [] | h::t -> t) matr)
fetch_column [] matrix
transpose [[1;2;3;4];[5;6;7;8];[9;10;11;12]]
|
val transpose : matrix:int list list -> int list list
Full name: Script.transpose
val matrix : int list list
val fetch_column : (int list list -> int list list -> int list list)
val acc : int list list
val matr : int list list
Multiple items
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
type 'T list = List<'T>
Full name: Microsoft.FSharp.Collections.list<_>
property List.Head: int list
property List.Length: int
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val rev : list:'T list -> 'T list
Full name: Microsoft.FSharp.Collections.List.rev
val row : int list
property List.Head: int
val map : mapping:('T -> 'U) -> list:'T list -> 'U list
Full name: Microsoft.FSharp.Collections.List.map
val h : int
val t : int list
More information