%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
F# for Scala developers
1. F# for Scala Developers
Walking into the dark side
meets
and Madrid Meetup groupsScala F#
2. How much do Scala and F# look alike?
Bring (non-strict) Functional Programming to Java and .NET
Full compatibility with their host platforms
Built-in functional libraries
Static safety with type inference
Mostly expression based (side-effects also allowed)
Open source projects with vibrant communities
3. How much do Scala and F# differ?
Scala
Embraces both Object Oriented and Functional Programming
Designed not to scare OOP developers: curly-brace
Very powerful and flexible syntax
Very rich class system
Language team works separately from Java team
4. How much do Scala and F# differ?
F#
Multi-paradigm but functional-first
Inherited from Ocaml: indentation sensitive
Less flexible syntax, more focused on consistency
Three flavors: project (.fs), script (.fsx) and signature (.fsi) files
Language team works together (more or less) with .NET team
Functional features like generics and tail-call
instructions are native to the platform
13. F#
As seen above, functions in F# are usually contained in modules
(curried by default)
Optional and rest parameters are only accepted in non-curried class
methods
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
14. Classes
Scala
Classes are very powerful in Scala and different from F#:
Singleton objects
Traits and abstract types
Compound types and mixins
15. F#
F# doesn't focus on classes
Their main purpose is compatibility with .NET Base Class Library
Mostly same functionality as C# with different Syntax and some
additional features (like primary constructors)
Interfaces are just abstract classes without default method
implementations
No mixins, only multiple interface implementation is possible
(extension methods are allowed)
Object Expressions allow dynamic implementation of interfaces
19. Tuples and Records
In F#, tuples, records (lightweight classes) and discriminated unions
(ADT) are usually preferred, with logic separated in module
functions.
21. F# Records
Named tuples or lightweight classes, if you must
1:
2:
3:
4:
5:
6:
7:
8:
9:
We can reach a similar effect in Scala marking constructor
parameters as fields
1:
2:
22. Algebraic Data Types and Pattern
Matching
Scala
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
29. Generics
F# generics are very similar to Scala, with a few diferences:
Automatic Generalization
If the function has no dependency on the specific type of a
parameter, the type is inferred to be generic
Statically Resolved Type Parameters
Type parameter replaced with actual types at compile time instead
of at run time
No generics of generics
Generics are native to .NET platform (no erasures) but on the
other hand are more limited (no type classes)
31. Instead, _map_ must be implemented for each type (or interface)
No generics of generics
Type classes like Functor are not allowed
1:
1:
2:
3:
32. Collections
F# built-in functions and operators and focus only on a few
collection types:
Immutable? Feature Scala
list Yes Linked list List
seq Yes Lazy evaluation Iterable/Stream
array No Random access Array
map Yes Indexed access Map
set Yes Unique items Set
35. F# Comprehensions
F# allows comprensions similar to those in Haskell or Python
1:
2:
3:
4:
5:
In Scala we would just use functions
1:
36. Observables
F# core library also includes support for Functional Reactive
Programming
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
37. More info about F# collections at Scott Wlaschin's site
Check also about the performance of
F# collection types
Phillip Trelford's presentation
38. Scala Comprehensions and F#
Computation Expressions
In Scala, any type implementing filterWith, map and flatMap can be
used with for comprehensions. This allows, for example, dealing
with async operations in a monadic way.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
39. In F#, this can be done using computation expressions
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Computation expressions convert language constructs like let, use,
do, for or try in for continuation passing style
operations
syntactic sugar
40. F# core has Asynchronous Workflows built-in
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Async<'T> is lazy, it will only start running after calling Async.Start or
Async.RunSynchronously
42. Query expressions
Query expressions provide support for LINQ in F#
1:
2:
3:
4:
5:
6:
They express transformations on a data source wich can be
translated to another language, usually SQL
1:
2:
3:
47. World Bank API REST
Watch to know more about type providersthis presentation
Type providers can also be emulated with Scala macros
48. Flagship Projects
Scala F#
Web ,
Actors
Big Data ,
Visualization
Play Lift Suave
Akka Akka.net
Spark Mbrace Prajna
Zeppelin FsLab
More at the F# space for incubating open
community projects
50. Want more F#?
Get started with
F# foundation
F# for Fun and Profit
F# Weekly
Ionide
These slides were made with and no
kittens were harmed in the process
FSReveal
51. And here comes the unasked-for advice!
Remember to focus away and when staring at the
screen for a long time
blink regularly
Ping me!
@alfonsogcnunez
,Github SlideShare