Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
FunScript: Why bother?
1. FunScript
F# to JavaScript with type providers
What is FunScript?
2. FunScript
F# to JavaScript with type providers
FunScript is...
yet another JavaScript compiler
So why bother?
3. FunScript
F# to JavaScript with type providers
It seems as if every programming language
in the world compiles now to JavaScript
And many of them are functional
o Elm
o LiveScript
o PureScript
o Fay
So, why bother with FunScript?
Reason #1...
4. FunScript
F# to JavaScript with type providers
THERE’S A F#er
WITHIN YOU
AND YOU KNOW IT
5. FunScript
F# to JavaScript with type providers
Free as in beer!
F# is a mature, open source, cross-platform,
functional-first programming language.
but also multi-paradigm
F# runs on Linux, Mac OS X, Android, iOS,
Windows as well as HTML 5 and GPUs.
And we all know when sth wants to conquerthe whole world is always a good thing
But enough of sales pitch!
6. FunScript
F# to JavaScript with type providers
SHOW ME DA GOODIES
7. FunScript
F# to JavaScript with type providers
Write F# client-side code in powerful IDEs
with autocomplete and tooltips
Intellisense is addictive!
No plugin required!
8. FunScript
F# to JavaScript with type providers
F# compiler is your best friend
It helps you write better code by pointing out your mistakes
If it were a human I would kill it
...but it’s not!
9. FunScript
F# to JavaScript with type providers
Usual functional stuff
• First-class and higher-order functions
• Immutability
• Recursion
• Pattern matching
• Type inference
Type safety
without the hassle
10. FunScript
F# to JavaScript with type providers
Functional data structures
• Tuples
• Records
• Discriminated Unions (Option built-in)
• Classes and Modules
• Functional collections
o Recursive lists
o Map
o Set
o seq
Never type
IEnumerable
again!
11. FunScript
F# to JavaScript with type providers
.NET mutable collections
• Array
• ResizeArray (mutable List)
• Dictionary They’ll compile as JS arrays and POJOs,
so they’re compatible with browser code
12. FunScript
F# to JavaScript with type providers
FunScript is compatible with many methods
of most used .NET classes
• Regular Expressions
• DateTime / TimeSpan
• String Formatting
• WebRequest Am I the only one with trouble
to remember how to use Regex
and Dates in each platform?
13. FunScript
F# to JavaScript with type providers
.NET Regular Expressions usage example
14. FunScript
F# to JavaScript with type providers
Click here for
a wonderful talk
F# unique features
o Type providers!
o Units of measure
o Computation expressions
15. FunScript
F# to JavaScript with type providers
And with FunScript.HTML extensions
you can create HTML 5 web apps
using your F#/.NET skills
Like...
16. FunScript
F# to JavaScript with type providers
Functional Reactive Programming (1)
Every element has
an equivalent extension
property to generate
an IObservable
17. FunScript
F# to JavaScript with type providers
Functional Reactive Programming (2)
Internal state
18. FunScript
F# to JavaScript with type providers
Functional Reactive Programming (and 3)
DateTime
String formatting
These extension methods
can easily be implemented
for other platforms
19. FunScript
F# to JavaScript with type providers
Asynchronous workflows (1)
Share types with LINQ to SQL, Web API and client code
LINQ, Web API and
FunScript do the tedious
marshaling work for you
20. FunScript
F# to JavaScript with type providers
Asynchronous workflows (2)
Asynchronous workflows are also very good
to handle events as you can use them
to represent a state-machine
Forget about “Inversion of Control”
Take the program flow control back!
21. FunScript
F# to JavaScript with type providers
Asynchronous workflows (and 3)
No flags needed!
22. FunScript
F# to JavaScript with type providers
Some people
still like
JS event
handling
though
23. FunScript
F# to JavaScript with type providers
So FunScript and FunScript.HTML
extensions allow you to:
o Minimize errors
o Reuse code
And most importantly...
o Reuse your skills
24. FunScript
F# to JavaScript with type providers
This is great. But...
There are wonderful JS libraries out there
Do I have to renounce to use them?
Nope!
FunScript offers wrappers for all definitions
in the TypeScript repository through NuGet
26. FunScript
F# to JavaScript with type providers
FunScript.HTML also offers deeper
integration with a great JavaScript
MVC framework:
Ractive.js
Check its wonderful website
to know more
27. FunScript
F# to JavaScript with type providers
Encapsulate state Async for events
and state updates
28. FunScript
F# to JavaScript with type providers
If necessary, you can extend FunScript
yourself easily
29. FunScript
F# to JavaScript with type providers
To be fair, there is also another F#
to JavaScript compiler out there:
WebSharper, a fantastic project
by IntelliFactory
Unlike FunScript, WebSharper is a
full-fledged web framework
A more detailed comparison follows.
30. FunScript
F# to JavaScript with type providers
Oh, c’mon!
FUNSCRIPT
FEATURES
Everything
you just saw
WEBSHARPER
FEATURES
Sorry, I haven’t
used it. Please
visit their site
and judge yourself
31. FunScript
F# to JavaScript with type providers
This is coming to an end
SAYONARA
BABY
That’s what he said in the Spanish version
32. FunScript
F# to JavaScript with type providers
FunScript has been created by Zach Bray
and several bright minds from the
F# community have contributed to it
▪ Tomas Petricek
▪ Robert Pickering
▪ James Freiwirth
Doesn’t it sound
like a Marvel
Hero name?
...more at funscript.info
33. FunScript
F# to JavaScript with type providers
And this presentation has been
assembled by yours truly,
Alfonso García-Caro
@alfonsogcnunez
github.com/alfonsogarciacaro
So now...
I’m also a
collaborator
now, but I’m
more of a
freeloader
34. FunScript
F# to JavaScript with type providers
WHAT THE
HELL ARE YOU
WAITING FOR