inkydragon / MLStyle.jl

ML language infrastructures in Julia that provide (generalized) algebraic data types abstraction, highly optimized and extensible pattern matching, and killer tools for meta-programming.

Home Page:https://thautwarm.github.io/MLStyle.jl/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MLStyle.jl

CI codecov License Docs Join the chat at https://gitter.im/MLStyle-jl/community

Providing intuitive, fast, consistent and extensible functional programming infrastructures, and metaprogramming facilities.

Check everything in the documentation website.

Preview

using MLStyle

@data Shape begin # Define an algebraic data type Shape
    Rock
    Paper
    Scissors
end

# Determine who wins a game of rock paper scissors with pattern matching
play(a::Shape, b::Shape) = @match (a, b) begin
    (Paper,    Rock)      => "Paper Wins!";
    (Rock,     Scissors)  => "Rock Wins!";
    (Scissors, Paper)     => "Scissors Wins!";
    (a, b)                => a == b ? "Tie!" : play(b, a)
end

P.S: When preferring Base.@enum than MLStyle.@data, you need this to pattern match on Julia Base.@enum.

Benchmarks

Arrays

matrix-benchmark/bench-array.jl

Tuples

matrix-benchmark/bench-tuple.jl

Data Types

matrix-benchmark/bench-datatype.jl

Extracting Struct Definitions

matrix-benchmark/bench-structfields.jl

Misc

matrix-benchmark/bench-misc.jl

An Example from Match.jl Documentation

matrix-benchmark/bench-versus-match.jl

Acknowledgements

Thanks to all individuals referred in Acknowledgements!

About

ML language infrastructures in Julia that provide (generalized) algebraic data types abstraction, highly optimized and extensible pattern matching, and killer tools for meta-programming.

https://thautwarm.github.io/MLStyle.jl/latest/

License:MIT License


Languages

Language:Julia 99.8%Language:Shell 0.2%