package feat-core

  1. Overview
  2. Docs

Source file IFSeqList.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(******************************************************************************)
(*                                                                            *)
(*                                     Feat                                   *)
(*                                                                            *)
(*                        François Pottier, Inria Paris                       *)
(*                                                                            *)
(*  Copyright Inria. All rights reserved. This file is distributed under the  *)
(*  terms of the MIT license, as described in the file LICENSE.               *)
(******************************************************************************)

(* No need to use unbounded integers here, since we will run out of time and
   memory before an overflow occurs. *)

type index =
  int

type 'a seq =
  'a list

let empty =
  []

let zero =
  empty

let singleton x =
  [x]

let one =
  singleton

let rev =
  List.rev

let sum =
  (@)

let ( ++ ) =
  sum

let product (s1 : 'a seq) (s2 : 'b seq) : ('a * 'b) seq =
  List.flatten (s1 |> List.map (fun x1 ->
    s2 |> List.map (fun x2 ->
      (x1, x2)
    )
  ))

let ( ** ) =
  product

let map =
  List.map

let rec up i j =
  if i < j then
    i :: up (i + 1) j
  else
    []

let length =
  List.length

let get =
  List.nth

let foreach s k =
  List.iter k s

let rec to_seq xs k =
  (* this is [Seq.of_list] *)
  fun () ->
    match xs with
    | [] ->
        k()
    | x :: xs ->
        Seq.Cons (x, to_seq xs k)