Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thautwarm/parameterisedmodule.jl
Full featured parameterised ML-modules in Julia
https://github.com/thautwarm/parameterisedmodule.jl
julia module-system ocaml parameterised
Last synced: about 1 month ago
JSON representation
Full featured parameterised ML-modules in Julia
- Host: GitHub
- URL: https://github.com/thautwarm/parameterisedmodule.jl
- Owner: thautwarm
- License: mit
- Created: 2019-11-11T08:42:50.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-08T16:05:55.000Z (almost 5 years ago)
- Last Synced: 2024-11-10T06:17:50.779Z (2 months ago)
- Topics: julia, module-system, ocaml, parameterised
- Language: Julia
- Size: 7.81 KB
- Stars: 9
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ParameterisedModule
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://thautwarm.github.io/ParameterisedModule.jl/stable)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://thautwarm.github.io/ParameterisedModule.jl/dev)
[![Build Status](https://travis-ci.com/thautwarm/ParameterisedModule.jl.svg?branch=master)](https://travis-ci.com/thautwarm/ParameterisedModule.jl)
[![Codecov](https://codecov.io/gh/thautwarm/ParameterisedModule.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/thautwarm/ParameterisedModule.jl)ML parameterised modules in Julia.
# APIs
- `@sig struct ... end` : define module signatures, like `sig` in OCaml.
- `@structure struct ... end` : define module structures, like `struct` in OCaml.
- `@open ModuleType Module` : using module, like `open` in OCaml.
- `@open ModuleType Module body` : using module when evaluating `body`, like `let open` in OCaml.# Non-Parametric Example
```julia
using ParameterisedModule# this is the module type declaration
@sig struct NatAlgebra
struct Eltype end # this is type declaration
succ :: Function
zero :: Eltype
end# make a module `num_nat`, whose module type is NatAlgebra
num_nat = @structure struct NatAlgebra
Eltype = Int
succ(x) = x + 1
zero = 0
end@open NatAlgebra num_nat begin
println(succ(succ(zero))) # 2
endprintln(succ(succ(zero)))
# ERROR: UndefVarError: succ not definedstr_nat = @structure struct NatAlgebra
Eltype = String
succ(x) = "succ($x)"
zero = "zero"
end@open NatAlgebra str_nat begin
println(succ(succ(zero))) # succ(succ(zero))
end
```# Parametric Examples
An example(word-algebra) from [the section *Algebra* of Oleg's tagless final lectures](http://okmij.org/ftp/tagless-final/Algebra.html).
```julia
Functor = Function
@sig struct TF{Eltype}
e :: Eltype
endTFZero(nat :: NatAlgebra) =
@structure struct TF{nat.Eltype}
e = nat.zero
endword_algebra =
@structure struct NatAlgebra
Eltype = Functor
zero = TFZero
succ(T1) =
function (N::NatAlgebra)
@structure struct TF{N.Eltype}
e = N.succ(T1(N).e)
end
end
end@sig struct H
h :: Function
endHTFC(N::NatAlgebra) =
@structure struct H
h(T) = T(N).e
endusing Test
@open H HTFC(num_nat) begin
@test h(word_algebra.zero) == num_nat.zerocase(x::Functor) =
h(word_algebra.succ(x)) == num_nat.succ(h(x))words = Functor[TFZero]
for i = 1:100
push!(words, word_algebra.succ(words[end]))
end
@test all(words) do x; case(x) end
end```