No matching definitions.

tur/gadt-vec

stdlib/gadt-vec.tur

length-indexed GVec GADT with phantom natural-number type parameter.

Since: Phase G4

defn

gvec-nil

(gvec-nil :GVec)

construct an empty GVec.

A (GVec int) value representing the empty list.

(gvec-nil)  ; => GVNil

Since: Phase G4

defn

gvec-cons

(gvec-cons [x :int v :GVec] :GVec)

prepend an integer element to a GVec.

xthe integer element to prepend
vthe existing (GVec int) to prepend onto

A new (GVec int) with x at the front.

(gvec-cons 1 (gvec-nil))  ; => GVCons(1, GVNil)

Since: Phase G4

defn

gvec-len

(gvec-len [v :GVec] :int)

compute the length of a GVec.

vthe (GVec int) to measure

The number of elements in v as an int.

(gvec-len (gvec-cons 1 (gvec-cons 2 (gvec-nil))))  ; => 2

Since: Phase G4

defn

gvec-sum

(gvec-sum [v :GVec] :int)

sum all elements of a GVec.

vthe (GVec int) to sum

The integer sum of all elements; 0 for an empty GVec.

(gvec-sum (gvec-cons 1 (gvec-cons 2 (gvec-cons 3 (gvec-nil)))))  ; => 6

Since: Phase G4

defn

gvec-head-or

(gvec-head-or [dflt :int v :GVec] :int)

return the first element or a default if empty.

dfltthe int value to return when v is empty
vthe (GVec int) to inspect

The head element of v if non-empty, otherwise dflt.

(gvec-head-or 99 (gvec-nil))                      ; => 99
  (gvec-head-or 99 (gvec-cons 5 (gvec-nil)))        ; => 5

Since: Phase G4

defn

gvec-tail

(gvec-tail [v :GVec] :GVec)

return all elements after the first.

vthe (GVec int) to take the tail of

The tail (GVec int) of v; GVNil if v is empty.

(gvec-tail (gvec-cons 1 (gvec-cons 2 (gvec-nil))))  ; => GVCons(2, GVNil)
  (gvec-tail (gvec-nil))                                ; => GVNil

Since: Phase G4

defn

gvmap

(gvmap [f :ptr<void> v] :GVec)

apply an int->int function to every element of a GVec.

fa curried int->int function (e.g. a partial application)
vthe (GVec int) to transform

A new (GVec int) with f applied to each element.

(defn mul [a :int b :int] :int (* a b))
  (gvec-sum (gvmap (mul 2) (gvec-cons 1 (gvec-cons 2 (gvec-nil)))))  ; => 6

Since: Phase G4

defn

gvzip-with

(gvzip-with [f :ptr<void> v1 v2] :GVec)

combine two GVecs element-wise using a binary int->int->int function.

fa two-argument function (int, int) -> int
v1the first (GVec int)
v2the second (GVec int)

A (GVec int) of combined values; stops at the shorter input.

(defn add [a :int b :int] :int (+ a b))
  (gvec-sum (gvzip-with add
              (gvec-cons 1 (gvec-cons 2 (gvec-nil)))
              (gvec-cons 10 (gvec-cons 20 (gvec-nil)))))  ; => 33

Since: Phase G4

Internal definitions
__gvec-call-fn1-- apply a ptr<void> closure to one int argument.