question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reconsider both curried and tupled overloads on dsharp.add etc.

See original GitHub issue

This pattern of having both curried and tupled methods is not recommended F# design and will likely cause problems (I noticed it in strange doc generation). I think we will probably have to just choose one or another

    static member add(a:Tensor, b:Tensor) = a.add(b)
    static member add(b:Tensor) = fun (a:Tensor) -> a.add(b)
    static member sub(a:Tensor, b:Tensor) = a.sub(b)
    static member sub(b:Tensor) = fun (a:Tensor) -> a.sub(b)
    static member mul(a:Tensor, b:Tensor) = a.mul(b)
    static member mul(b:Tensor) = fun (a:Tensor) -> a.mul(b)
    static member div(a:Tensor, b:Tensor) = a.div(b)
    static member div(b:Tensor) = fun (a:Tensor) -> a.div(b)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
dsymecommented, Sep 7, 2020

Proposal from discussion with @gbaydin - make an explicit open to get the pipelined notation

    t.dropout()
    t.dropout(0.5)

    dsharp.dropout (t, 0.5) // never used in documentation (curried, no pipeline)

    open DiffSharp.Pipelined
    t |> dsharp.dropout()
    t |> dsharp.dropout(0.5)
1reaction
dsymecommented, Aug 26, 2020

Is the problem only about the documentation?

There are multiple potential problems:

  1. Order of arguments is confusing, e.g. dsharp.sub x y is y - x not x - y. That’s really very confusing to people, and there’s nothing to force currying to be used for this overload. It’s ok for the API author - they know what to do - but other people won’t get this.

  2. F# type inference and tooling is not really designed for APIs like this. I just don’t know if it will be that great. Certainly F# type inference just works much better if there are fewer overloads. Also will parameter help work? I don’t know.

  3. 2x the documentation

  4. It might be fine for div/add/mul/… etc. with two arguments but get whacky with other things that have more arguments. What’s the general rule?

  5. Intellisense will be more confusing to people. 2x the entries and they won’t know which to choose

  6. The curried methods will look confusing to people in intellisense

  7. If we add shape inference, then we have 2x the API surface area

  8. Too many ways to do the same thing

  9. Are user-defined binary operators also meant to follow this pattern?

Of these (1) is to me too severe to embrace this on anything non-commutative.

There’s commonly also a problem where things like this combine: a 2x multiplication of your API surface area becomes 4x then 8x… when combined with something else (like overloading on scalars).

Anyway I’d recommend against building this in for now for all the above reason. In your example just write the lambda

else d.valuesTensor.unstack() |> Seq.map f |> dsharp.stack |> (fun t -> t.mean(0))

and separately advocate for solving this at the F# language level, e.g. via _.x(args) notation:

else d.valuesTensor.unstack() |> Seq.map f |> dsharp.stack |> _.mean(0)
Read more comments on GitHub >

github_iconTop Results From Across the Web

F#: curried overload/tupled overload issue
The reason for the change is in the detailed release notes: Optimizations for Curried Methods. A curried member looks like this: type C()...
Read more >
Dependently Typed Programming with Domain-Specific Logics
The central notion in logic is consequence—entailment from premises to conclusions—and two notions of conse- quence are necessary for ...
Read more >
The Glorious Glasgow Haskell Compilation System User's ...
GHC has two main components: an interactive Haskell interpreter (also known as GHCi), described in Chapter 2, and a batch.
Read more >
The Haskell School of Music - Computer Science
ample, it does not make much sense to add together two characters, so the expression 'a'+'b' is ill-typed. The best news is that...
Read more >
Church Board WE FOUND DREAM HOME OF OUR
the local high school last rear, la back as a member of the regular teaching staff and has tba B squad freshmen and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found