Giter VIP home page Giter VIP logo

Comments (6)

JeffBezanson avatar JeffBezanson commented on April 28, 2024

This is a throwaway issue. This needs a real proposal or some examples.

For functions, we would need to group patterns by type and convert the dynamic part (the part the type system doesn't model) to run-time checks:

f(x::2) = 0
f(x::3) = 1

becomes

f(x::Int32) = (x==2 ? 0 : (x==3 ? 1 : ... ))

This is really complex and makes it perhaps too easy to write overlapping or conflicting definitions. For example, you wouldn't implement +(x::Int,y::Int) = ... unless you really knew what you were doing, but it seems easier to write +(x::2, y::3) = 42. It's a silly example but you get the idea.

Another problem is that we don't have record literals, or structurally-typed records. So something like "name::String, age::Number" is not a type. As I said at one point, we could add records like this, which are basically tuples with named components. These are to keyword arguments exactly what tuples are to positional arguments, which has a certain elegance. But it just seems like too many features.

from julia.

StefanKarpinski avatar StefanKarpinski commented on April 28, 2024

These are the reasons why I made this a v2.0 issue and a speculative one. It's really just a placeholder for keeping the possibility in mind. Maybe we have a much more limited notion of pattern matching, but using the same approach for case statements and catch blocks seems sensible. We already have limited destructuring for tuples.

from julia.

si14 avatar si14 commented on April 28, 2024

+1 here :)

from julia.

friggeri avatar friggeri commented on April 28, 2024

I'd rather see something along the lines of :

f(2::Int) = 0
f(3::Int32) = 1

f(2) # -> 0
f(3::Int64) # -> no method f(3::Int64)

from julia.

JeffBezanson avatar JeffBezanson commented on April 28, 2024

Yes that syntax makes more sense.

from julia.

JeffBezanson avatar JeffBezanson commented on April 28, 2024

I don't think we need an issue to keep track of this idea.

from julia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.