[ANN] QuickTypes.jl: Concise type definitions with default arguments

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[ANN] QuickTypes.jl: Concise type definitions with default arguments

Cedric St-Jean-2
Types are central to Julia programming, but the built-in `type` and `immutable` definitions can be cumbersome to write. QuickTypes.jl provides two alternative macros, @qtype and @qimmutable, with a more convenient syntax:

Pkg.add("QuickTypes")   # to install
using QuickTypes

@qtype Wall(width, height)

# Optional and keyword-arguments
@qtype Cat(name, age::Int, nlegs=4; species="Siamese")

# Parametric type
@qtype Pack{T}(animals::Vector{T})

# Inheritance
abstract Tree
@qtype Maple(qty_syrup::Float64) <: Tree

# Immutables work the same way
@qimmutable SquaredNumber(x2::Number)

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] QuickTypes.jl: Concise type definitions with default arguments

Jake Rosoman
Good idea! I think more self explanatory naming would be @deftype and @defimmutable though

On Wednesday, October 26, 2016 at 4:00:13 AM UTC+13, Cedric St-Jean wrote:
Types are central to Julia programming, but the built-in `type` and `immutable` definitions can be cumbersome to write. <a href="https://github.com/cstjean/QuickTypes.jl" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;">QuickTypes.jl provides two alternative macros, @qtype and @qimmutable, with a more convenient syntax:

Pkg.add("QuickTypes")   # to install
using QuickTypes

@qtype Wall(width, height)

# Optional and keyword-arguments
@qtype Cat(name, age::Int, nlegs=4; species="Siamese")

# Parametric type
@qtype Pack{T}(animals::Vector{T})

# Inheritance
abstract Tree
@qtype Maple(qty_syrup::Float64) <: Tree

# Immutables work the same way
@qimmutable SquaredNumber(x2::Number)

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] QuickTypes.jl: Concise type definitions with default arguments

Jake Rosoman
Or even @Type and @Immutable

On Sunday, October 30, 2016 at 11:12:47 AM UTC+13, Jake Rosoman wrote:
Good idea! I think more self explanatory naming would be @deftype and @defimmutable though

On Wednesday, October 26, 2016 at 4:00:13 AM UTC+13, Cedric St-Jean wrote:
Types are central to Julia programming, but the built-in `type` and `immutable` definitions can be cumbersome to write. <a href="https://github.com/cstjean/QuickTypes.jl" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;">QuickTypes.jl provides two alternative macros, @qtype and @qimmutable, with a more convenient syntax:

Pkg.add("QuickTypes")   # to install
using QuickTypes

@qtype Wall(width, height)

# Optional and keyword-arguments
@qtype Cat(name, age::Int, nlegs=4; species="Siamese")

# Parametric type
@qtype Pack{T}(animals::Vector{T})

# Inheritance
abstract Tree
@qtype Maple(qty_syrup::Float64) <: Tree

# Immutables work the same way
@qimmutable SquaredNumber(x2::Number)

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] QuickTypes.jl: Concise type definitions with default arguments

Fengyang Wang
It is also possible to use @type and @immutable, although the macros are slightly harder to define.

macro lit_str(s); Symbol(s); end

macro lit
"type"(x)
   
...
end

macro lit
"immutable"(x)
   
...
end

@type ...
@immutable ...



On Saturday, October 29, 2016 at 6:16:37 PM UTC-4, Jake Rosoman wrote:
Or even @Type and @Immutable

On Sunday, October 30, 2016 at 11:12:47 AM UTC+13, Jake Rosoman wrote:
Good idea! I think more self explanatory naming would be @deftype and @defimmutable though

On Wednesday, October 26, 2016 at 4:00:13 AM UTC+13, Cedric St-Jean wrote:
Types are central to Julia programming, but the built-in `type` and `immutable` definitions can be cumbersome to write. <a href="https://github.com/cstjean/QuickTypes.jl" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;">QuickTypes.jl provides two alternative macros, @qtype and @qimmutable, with a more convenient syntax:

Pkg.add("QuickTypes")   # to install
using QuickTypes

@qtype Wall(width, height)

# Optional and keyword-arguments
@qtype Cat(name, age::Int, nlegs=4; species="Siamese")

# Parametric type
@qtype Pack{T}(animals::Vector{T})

# Inheritance
abstract Tree
@qtype Maple(qty_syrup::Float64) <: Tree

# Immutables work the same way
@qimmutable SquaredNumber(x2::Number)

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] QuickTypes.jl: Concise type definitions with default arguments

Scott Jones
In reply to this post by Cedric St-Jean-2
Maybe `@mutable` instead of `@qtype` or `@type`, to reflect Jeff's PR to change the `type` keyword to `mutable`, making the naming consistent

On Tuesday, October 25, 2016 at 11:00:13 AM UTC-4, Cedric St-Jean wrote:
Types are central to Julia programming, but the built-in `type` and `immutable` definitions can be cumbersome to write. <a href="https://github.com/cstjean/QuickTypes.jl" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;">QuickTypes.jl provides two alternative macros, @qtype and @qimmutable, with a more convenient syntax:

Pkg.add("QuickTypes")   # to install
using QuickTypes

@qtype Wall(width, height)

# Optional and keyword-arguments
@qtype Cat(name, age::Int, nlegs=4; species="Siamese")

# Parametric type
@qtype Pack{T}(animals::Vector{T})

# Inheritance
abstract Tree
@qtype Maple(qty_syrup::Float64) <: Tree

# Immutables work the same way
@qimmutable SquaredNumber(x2::Number)

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] QuickTypes.jl: Concise type definitions with default arguments

Stefan Karpinski
That wasn't a PR, it was a "crazy idea" issue. Please stop spreading bogus news of change before anything has been decided, let alone happened.

On Sunday, October 30, 2016, Scott Jones <[hidden email]> wrote:
Maybe `@mutable` instead of `@qtype` or `@type`, to reflect Jeff's PR to change the `type` keyword to `mutable`, making the naming consistent

On Tuesday, October 25, 2016 at 11:00:13 AM UTC-4, Cedric St-Jean wrote:
Types are central to Julia programming, but the built-in `type` and `immutable` definitions can be cumbersome to write. QuickTypes.jl provides two alternative macros, @qtype and @qimmutable, with a more convenient syntax:

Pkg.add("QuickTypes")   # to install
using QuickTypes

@qtype Wall(width, height)

# Optional and keyword-arguments
@qtype Cat(name, age::Int, nlegs=4; species="Siamese")

# Parametric type
@qtype Pack{T}(animals::Vector{T})

# Inheritance
abstract Tree
@qtype Maple(qty_syrup::Float64) <: Tree

# Immutables work the same way
@qimmutable SquaredNumber(x2::Number)

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] QuickTypes.jl: Concise type definitions with default arguments

Stefan Karpinski
The issue in question in case anyone is curious: https://github.com/JuliaLang/julia/issues/19157.

On Sunday, October 30, 2016, Stefan Karpinski <[hidden email]> wrote:
That wasn't a PR, it was a "crazy idea" issue. Please stop spreading bogus news of change before anything has been decided, let alone happened.

On Sunday, October 30, 2016, Scott Jones <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;scott.paul.jones@gmail.com&#39;);" target="_blank">scott.paul.jones@...> wrote:
Maybe `@mutable` instead of `@qtype` or `@type`, to reflect Jeff's PR to change the `type` keyword to `mutable`, making the naming consistent

On Tuesday, October 25, 2016 at 11:00:13 AM UTC-4, Cedric St-Jean wrote:
Types are central to Julia programming, but the built-in `type` and `immutable` definitions can be cumbersome to write. QuickTypes.jl provides two alternative macros, @qtype and @qimmutable, with a more convenient syntax:

Pkg.add("QuickTypes")   # to install
using QuickTypes

@qtype Wall(width, height)

# Optional and keyword-arguments
@qtype Cat(name, age::Int, nlegs=4; species="Siamese")

# Parametric type
@qtype Pack{T}(animals::Vector{T})

# Inheritance
abstract Tree
@qtype Maple(qty_syrup::Float64) <: Tree

# Immutables work the same way
@qimmutable SquaredNumber(x2::Number)

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] QuickTypes.jl: Concise type definitions with default arguments

Cedric St-Jean-2
I like @type and @immutable, but I would worry about using reserved keywords for a macro name. It might mess up other parsers (for syntax highlighting, indentation). `qtype` is serviceable for now. When/if `type` gets renamed in Julia, I will reconsider...

On Sunday, October 30, 2016 at 12:47:22 PM UTC-4, Stefan Karpinski wrote:
The issue in question in case anyone is curious: <a href="https://github.com/JuliaLang/julia/issues/19157" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FJuliaLang%2Fjulia%2Fissues%2F19157\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJxLMSXLAJ3CMm3Zaqo7XaVhowug&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FJuliaLang%2Fjulia%2Fissues%2F19157\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJxLMSXLAJ3CMm3Zaqo7XaVhowug&#39;;return true;">https://github.com/JuliaLang/julia/issues/19157.

On Sunday, October 30, 2016, Stefan Karpinski <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="CUVm8n0BAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ste...@...> wrote:
That wasn't a PR, it was a "crazy idea" issue. Please stop spreading bogus news of change before anything has been decided, let alone happened.

On Sunday, October 30, 2016, Scott Jones <<> wrote:
Maybe `@mutable` instead of `@qtype` or `@type`, to reflect Jeff's PR to change the `type` keyword to `mutable`, making the naming consistent

On Tuesday, October 25, 2016 at 11:00:13 AM UTC-4, Cedric St-Jean wrote:
Types are central to Julia programming, but the built-in `type` and `immutable` definitions can be cumbersome to write. <a href="https://github.com/cstjean/QuickTypes.jl" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcstjean%2FQuickTypes.jl\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFEt-Zhjqv_04jAnEAj4ZOg8G8ocA&#39;;return true;">QuickTypes.jl provides two alternative macros, @qtype and @qimmutable, with a more convenient syntax:

Pkg.add("QuickTypes")   # to install
using QuickTypes

@qtype Wall(width, height)

# Optional and keyword-arguments
@qtype Cat(name, age::Int, nlegs=4; species="Siamese")

# Parametric type
@qtype Pack{T}(animals::Vector{T})

# Inheritance
abstract Tree
@qtype Maple(qty_syrup::Float64) <: Tree

# Immutables work the same way
@qimmutable SquaredNumber(x2::Number)