fable-compiler / fable-react-native

Fable bindings and helpers for React Native projects
Apache License 2.0
49 stars 11 forks source link

Question about Func's #24

Closed iyegoroff closed 6 years ago

iyegoroff commented 6 years ago

Why do you use types like Func<x, y, z> instead of (x -> y -> z) almost everywhere? It seems that second signature is easier to use:

with Func's

let renderItem (item: FlatListRenderItemInfo<'a>) =
  //...

R.flatList items
  [ RenderItem (Func<_, _>renderItem)
    KeyExtractor (Func<_, _, _>(fun item _ -> itemKey item)) ]

with arrows

let renderItem (item: FlatListRenderItemInfo<'a>) =
  //...

R.flatList items
  [ RenderItem renderItem
    KeyExtractor (fun item _ -> itemKey item) ]
forki commented 6 years ago

/cc @alfonsogcnunez @MangelMaxime

iyegoroff notifications@github.com schrieb am Mo., 11. Juni 2018, 04:52:

Why do you use types like Func<x, y, z> instead of (x -> y -> z) almost everywhere? It seems that second signature is easier to use:

with Func's

let renderItem (item: FlatListRenderItemInfo<'a>) = //...

R.flatList items [ RenderItem (Func<, >renderItem) KeyExtractor (Func<, , >(fun item -> itemKey item)) ]

with arrows

let renderItem (item: FlatListRenderItemInfo<'a>) = //...

R.flatList items [ RenderItem renderItem KeyExtractor (fun item _ -> itemKey item) ]

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fable-compiler/fable-react-native/issues/24, or mute the thread https://github.com/notifications/unsubscribe-auth/AADgNEswsJeuLm_ZkiolRI-jmtbWb0v4ks5t7dtygaJpZM4Uh_4R .

Zaid-Ajaj commented 6 years ago

@iyegoroff if Func is being used in the API then it is out-dated. x -> y -> z should be used because it compiles down to the uncurried version of the function i.e. function (x, y) { return z; } for better inter-operability and it can still be partially applied.

alfonsogarciacaro commented 6 years ago

It's as @Zaid-Ajaj says :) Originally Fable compiled curried F# functions as nested JS anonymous functions (x => y => z) so we used Func<int,int,int> to indicate the function wasn't curried. In most cases the conversion from curried F# function to Func (aka delegate in .NET) was done automatically by the F# compiler but in others it was hindering usability, so from Fable 1.x on, we're trying not to compile curried functions as nested lambdas. And in most cases you don't need to use Func in signatures any more.

iyegoroff commented 6 years ago

@Zaid-Ajaj , @alfonsogarciacaro thanks for the answers!