Define polymorphic lenses and compile the runtime library
This commit is contained in:
9 files changed
+61
No files matched your search
@@ -0,0 +1,5 @@
|
||||
*.cmi
|
||||
*.cmo
|
||||
*.cma
|
||||
*.byte
|
||||
rewrite
|
||||
@@ -0,0 +1,3 @@
|
||||
version = "0.1.0"
|
||||
description = "Record accessors and composable lenses"
|
||||
archive(byte) = "fieldglass.cma"
|
||||
@@ -0,0 +1,20 @@
|
||||
OCAMLC ?= ocamlc
|
||||
|
||||
.PHONY: all test clean
|
||||
all: fieldglass.cma
|
||||
|
||||
fieldglass.cmi: fieldglass.mli
|
||||
$(OCAMLC) -c $<
|
||||
|
||||
fieldglass.cmo: fieldglass.ml fieldglass.cmi
|
||||
$(OCAMLC) -c $<
|
||||
|
||||
fieldglass.cma: fieldglass.cmo
|
||||
$(OCAMLC) -a $< -o $@
|
||||
|
||||
test: all
|
||||
$(OCAMLC) fieldglass.cma runtime.ml -o runtime.byte
|
||||
./runtime.byte
|
||||
|
||||
clean:
|
||||
rm -f *.cmi *.cmo *.cma *.byte rewrite
|
||||
@@ -0,0 +1,5 @@
|
||||
# fieldglass
|
||||
|
||||
Lenses for reading and updating immutable data in OCaml.
|
||||
|
||||
Build with `make`; run the checks with `make test`.
|
||||
@@ -0,0 +1 @@
|
||||
lib: ["fieldglass.cmi" "fieldglass.cma" "fieldglass.mli" "META"]
|
||||
@@ -0,0 +1,5 @@
|
||||
type ('s, 't, 'a, 'b) lens = ('s -> 'a) * ('b -> 's -> 't)
|
||||
type ('s, 'a) lens' = ('s, 's, 'a, 'a) lens
|
||||
|
||||
let lens ~view ~set = view, set
|
||||
let view (get, _) = get
|
||||
@@ -0,0 +1,5 @@
|
||||
type ('s, 't, 'a, 'b) lens = ('s -> 'a) * ('b -> 's -> 't)
|
||||
type ('s, 'a) lens' = ('s, 's, 'a, 'a) lens
|
||||
|
||||
val lens : view:('s -> 'a) -> set:('b -> 's -> 't) -> ('s, 't, 'a, 'b) lens
|
||||
val view : ('s, 't, 'a, 'b) lens -> 's -> 'a
|
||||
@@ -0,0 +1,11 @@
|
||||
opam-version: "1.2"
|
||||
name: "fieldglass"
|
||||
version: "0.1.0"
|
||||
maintainer: "rack"
|
||||
authors: ["rack"]
|
||||
homepage: "https://github.com/rackquiem/fieldglass"
|
||||
bug-reports: "https://github.com/rackquiem/fieldglass/issues"
|
||||
dev-repo: "git+https://github.com/rackquiem/fieldglass.git"
|
||||
build: [make]
|
||||
build-test: [make "test"]
|
||||
available: [ocaml-version = "4.06.1"]
|
||||
@@ -0,0 +1,6 @@
|
||||
open Fieldglass
|
||||
|
||||
let sample : (string * bool, string) lens' =
|
||||
lens ~view:fst ~set:(fun value (_, other) -> value, other)
|
||||
|
||||
let () = assert (view sample ("colour", true) = "colour")
|
||||
Reference in new issue
Block a user