Giter VIP home page Giter VIP logo

partialfunctions.jl's People

Contributors

archermarx avatar avik-pal avatar mrbreadwater avatar mroqueta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mroqueta avik-pal

partialfunctions.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Feature request: Placeholder operator

Hello.

Over the last weeks, I ended up creating my own partial application package. One interesting feature I managed to implement that I think is pretty cool is a special "placeholder constant". It acts very similar to the _ in your @$-macro.

As an example, look at this:

greeter = println ¦ "Hello, " ¦ ⎵ ¦ ", nice to meet you!" 

greeter("bobby")
# ->Hello, bobby, nice to meet you!

greeter("peter", " Have a nice Day")
# ->Hello, peter, nice to meet you! Have a nice Day

The ¦ in my code has the same role as $ in your package. The is my placeholder constant, signifying that an argument should be supplied here.

If you want to implement this feature, one thing to consider is the name of this constant. Some suggestions:

  1. use (\underbracket) like I did. Advantages: expressive, the function of this is visually very obvious, unlikely to clash with other definitions made by the user/other packages loaded by the user. Disadvantage: People without IDE support (VSCode, Neovim, Jupyter) will have difficulty typing this character, as it is not part of any keyboard I know of.
  2. use something like _! (_ itself is not possible). Advantage: still somewhat expressive, sidesteps the problem from the last point. Disadvantage: pretty ugly!
  3. come up with something yourself...

The fact that there is a placeholder and its position should be accessible in the type signature, so code generation can make use of this and shuffle the arguments accordingly at compile time.

As in my last issue, I would supply this as a PR myself, but I am a bit short on time recently, and the way I have structured my package is quite a bit different to yours, so some adaptation is needed. I will give you a link to my code, if you want to do this you can use whatever you like from it, it is pretty simple and well documented. The relevant code is anything involving the type ReserveFunc. Anything past line 110 is just pretty printing and can be ignored.

Link: https://github.com/arikheinss/PartialApplication.jl/blob/main/src/PartialApplication.jl

Performance regression due to blocking out constant propagation

Hello once more,

I noticed another source of performance regression when using partial functions compared to native anonymous functions x -> ...., which is that partial functions may lock the compiler out of some of its optimization routines. I documented my findings in details in a topic on discourse here.

As mentioned in the topic, AFAIK there is no solution to this problem that could be employed for your package, but I thought as the maintainer maybe you would want to know about the issue.

That is all for now. Cheers, and merry christmas!

flip method not exported on Julia v1.6

On Julia v1.6 it seems the flip method is not exported by the PartialFunctions module for me, I get the following

julia> names(PartialFunctions)
3-element Vector{Symbol}:
 :$
 :<|
 :PartialFunctions

I cloned the package and made a change to the export statement on PartialFunctions.jl, from

export $, <|

to

export $
export <|

and it seemed to solve the problem, although I am not sure why. I can make a pull request with the changes.
Thanks!

Performance regression when partially applying types

Hello.

I have noticed pretty significant performance regressions when partially applying data types, like convert $ Float64, round $ Int, parse $ Int etc. To reproduce, take this as an example:

using PartialFunctions, BenchmarkTools
data = rand(1:20, 1000) .|> string

@btime val_native = mapreduce( x -> parse(Int, x), +, data)
# -> 18.243 μs (1 allocation: 16 bytes)

@btime val_partial = mapreduce( parse $ Int, +, data)
# -> 129.363 μs (958 allocations: 14.98 KiB)

The reason for this can be found when inspecting the type:

typeof(parse $ Int)
# -> PartialFunctions.PartialFunction{nothing, nothing, typeof(parse), Tuple{DataType}, NamedTuple{(), Tuple{}}}

Notice the Tuple{DataType} in there. When compiling all the compiler sees is this signature: parse(::DataType, ::String), which is not enough information to compile type stable code.
The reason that happens is that

typeof(Int) # -> DataType
# same for all other data types

and that DataType is technically a concrete type but practically not really. Ideally this should be replaced with Type{Int}.

One way to fix this would be to supply a new specialized method for the $ function,

($)(f::Function, ::Type{T}) where T = ...

wherein the type parameter is manually set to Type{T}.

This problem has been solved before by the Fix1 type, see here.

Alternatively, I experimentally created my own partial application package. You can have a look how I solved the problem here.

I would offer the PR with a fix myself, but I have had very little time for hobby programming the past weeks, so I decided to just notify you about the problem instead 🤷‍♂️.

Is there a way to run a function once the number of arguments "saturates"?

Hey, thanks for this package! I've been playing around with it in order to implement some functional programming stuff.
I was wondering if there is a way to run a function that has a limited amount of arguments, without having to explicitly call the <| (). For example

f(x,y) = 2(x+y)
f $ 1 $ 2 # This should immediately run the function

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.