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.

What' the meta programming story in Fable 2.0?

See original GitHub issue

I’m playing with F#'s quotation feature recently, and I find it’s really powerful because we can create a lambda function based on expression tree and eval it to a real function, this is much like macros in other languages. Unfortunately, it’s unavailable in Fable.

Here are some cases that I would use some equivalent feature in Fable:

1. Create default empty record.

type People = {
  name: string
  age: int
}
module People = 
  let empty = 
    { name = ""
       age = 0 }

In F#, I need to write lots’ of empty record, it could actually be done by Reflection or quotations, but Fable’s reflection API is very limit, I’m not sure there is a way to do this. And since Fable 2.0 will use more lightweight types, plugins API with full access to generic type info might be a good idea.

2. Create functions dynamically

I usually create lots of Records/Classes, like BookInput (book model for input form), BookOutput(book model for output), BookEntity (book entity for ORM) and need write lots of functions to transform between them. The transform functions can be generated by quotations, but there still are some in fables that I’m not sure how to implement, like BookOutput -> BookInput.

Fable’s interop API is very powerful and convenient, but as same as No.1, without type information it could be really hard to handle FSharp values/types.

I know reflection, plugins are not included in the alpha release, but maybe it’s the time for discussion? 😄

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
alfonsogarciacarocommented, Mar 23, 2018

@Zaid-Ajaj For that, we need to add first the metadata before making it optional 😃 But in any case, I don’t think it’s a question of all or nothing, because in most cases users would need reflection for only a few types. Also, just to let you know, I’m very interested in making Fable.Remoting work with Fable 2 (stable) out-of-box or with little changes. I already had a look at the source and I will try to find if it’s possible to resolve the needed reflection info at compile time.

@zaaack I’m not totally sure, but I guess TP accept types as static parameters. Attribute constructor arguments are also static and beside literals (strings and numbers) they also accept types.

1reaction
michaelsgcommented, May 5, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing Fable 2.0 beta
Fable 2 now will convert most of the methods (be it class or nested module members) into functions of the JS file module....
Read more >
What I wish I knew when learning F#
It has relatively weak metaprogramming capabilities and it doesn't have higher kinded types. This means that there is a ceiling to the ...
Read more >
The Features Threads Could Roll Out Next
Meta announced it will soon offer disappearing Stories and short-form Reels in chronological order, along with other changes, to comply with the ...
Read more >
“Wolves In The Walls” Launches On Oculus Quest
The story starts with Lucy sharing that she hears “wolves” in the walls of her house but no-one in her family believes her....
Read more >
Tagged f# - Latest writings from my blog
We use lightweight meta-programming for targeting JavaScript and computation expressions for writing asynchronous code. This blog post is a shorter version ...
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