Date post: | 10-May-2015 |
Category: |
Technology |
Upload: | rystsov |
View: | 2,871 times |
Download: | 5 times |
Nemerle is notable
Nemerle is notable
Denis Rystsovtwitter.com/rystsov
2011
Nemerle is notable
Origin
Nemerle is notable
Nemerle Experience
Nemerle is notable
EnvironmentManaged compiler written in Nemerle
Visual Studio 2008 plugin with debugger and autocomplete
Free IDE based on Visual Studio Isolated Shell
Sharpdevelop plugin
Mono support
NAnt plugin
Nemerle is notable
Why not try?
Nemerle is almost a superset ofC#, so if you know C# you canuse Nemerle.
Nemerle is notable
Why not try?
By the way, Nemerle's compilercan compile C# code, so youcan try it on exising C# project
Nemerle is notable
Why not try?
Why not try?
Nemerle is notable
Part I - use your C# habits
Part I - use your C# habits
Nemerle is notable
Hello world / C#
Nemerle is notable
Hello world / Nemerle
Nemerle is notable
Extension Methods / C#
Nemerle is notable
Extension Methods / Nemerle
Nemerle is notable
LINQ / C#
Nemerle is notable
LINQ / Nemerle
Nemerle is notable
Object Initialization / C#
Nemerle is notable
Object Initialization / Nemerle
Nemerle is notable
Anonymous Types / C#
Nemerle is notable
Anonymous Types / Nemerle
Nemerle is notable
Yield return / C#
Nemerle is notable
Yield return / Nemerle
Nemerle is notable
Dynamic / C#
Nemerle is notable
Dynamic / Nemerle
Nemerle is notable
Type casting / C#
Nemerle is notable
Type casting / Nemerle
Nemerle is notable
Try..Catch / C#
Nemerle is notable
Try..Catch / Nemerle
Nemerle is notable
Partial / C#
Nemerle is notable
Partial / Nemerle
Nemerle is notable
Arrays / C#
Nemerle is notable
Arrays / Nemerle
Nemerle is notable
Attention! Wild dinosaur!
Nemerle is notable
Goto?
What is about..
GOTO?unlike C# Nemerle doesn't support it, but..
Nemerle is notable
The proper use of goto
The only one legal usage of goto is
exit from nested loops
Nemerle provides a bettersolution � named code blocks
Nemerle is notable
Named code blocks
Nemerle is notable
Beyond C#
After this short intro you canwrite apps in Nemerle in C#style.
But Nemerle goes far beyond it
Nemerle is notable
Desired C# features
Itsupportsthe most desiredfeatures of the nextversions of C# right now
Nemerle is notable
Part II - desired C# features
Part II - desired C# features
Nemerle is notable
Object initializers with events
Nemerle is notable
Painless XML generation
Nemerle is notable
INotifyPropertyChanged language support
Nemerle is notable
`Safe navigation' operator
Nemerle is notable
Design by contract
Nemerle is notable
Sequence initialization (list comprehension)
Nemerle is notable
Yield from lambda
Nemerle is notable
Improved lazy support
Nemerle is notable
Part III � functional programming
Part III � functionalprogramming (FP)
Nemerle is notable
What is FP?
Typical signs of FPMonadsType inferencePattern matchingAlgebraic data typesBuilt-in tuple supportLocal (nested) functions
Nemerle is notable
Nemerle supports FP
Nemerle supports it all
Nemerle is notable
Type inference
Nemerle is notable
Local functions
Nemerle is notable
Built-in tuple support
Nemerle is notable
Monads
Monad is creational functional programming designpattern that deals with computation creation.
The upcoming C# 5 async/await feature is particularcase of a monad (creation of asynchronouscomputation).
Computation expressions are monads + monoids.
Nemerle supports computation expressions.
Nemerle is notable
Monads
Consequently Nemerle supportsthe upcoming C# 5async/await feature right nowamong the other monads.
Nemerle is notable
Example of easy composition of two async methods
Nemerle is notable
Algebraic data types
Short intro toalgebraic data types
Nemerle is notable
Algebraic data types
Let's learn ADT by example
Suppose we need to work withexpressions like
a + sin(b)
Nemerle is notable
Algebraic data type
Of couse we need trees
Nemerle is notable
OOP approach to trees (class hierarchy)
Nemerle is notable
FP approach to trees (ADT - algebraic data type)
Nemerle is notable
Algebraic data type � semantic
After we rewrite OOP code with variant (ADT) weshould consider`Sum' as a constructor of type `Tree'`l',`r' as its params (not a Tree.Sum's �elds)
But if they are params, how get them back from a`Tree' typed object?
Nemerle is notable
Algebraic data type � Disassembling (pattern matching)
Pattern matching solves this problem. It checks if object isconstructed with constructor speci�ed in a pattern and if it is trueit binds actual parameters of constructor with names of variablesthe pattern.
Let's see on the following example.
Nemerle is notable
Pretty Printing of `Tree' typed object
Nemerle is notable
Algebraic data type � OOP vs. FP
OOP
72 SLoC (pretty printing withvisitor pattern)
FP
25 SLoC (pretty printing withpattern matching)
Nemerle is notable
Variant is OOP enabled algebraic data type
Nemerle is notable
Pattern matching goes beyond disassembling
Pattern matching can be nested.
Nemerle is notable
Almost all features are macros
Nemerle seems to be complex,but. . .
Nemerle is notable
Almost all Nemerle features are macros
Don't worryNemerle is a simple language and almost all features aremacros � parts of standard library, not a language.
Macros is a plugin to compiler. You can write your ownmacros to introduce new language constructs or eDSL.
Nemerle is notable
Almost all Nemerle features are macros
You've already meet macros inthis presentation, they are. . .
Nemerle is notable
Almost all Nemerle features are macros
LINQ Object initialization Anonymous typesLate (dynamic) XML-LiteralsINotifyPropertyChanged macro Safe navigationDesign by contract Computation expressionsLazy macro
and even
if while foreach
Nemerle is notable
Advanced macros
Beside macros copying useful features from anotherlanguages there are macros adding unique features.
One of them is Nemerle.Peg. It is a macro-librarythat allows to describe grammar in the attribute andduring the compilation necessary methods for parsingtext in this grammar will be added to the class.
Also there are some macros supporting designpatterns.
Nemerle is notable
Nemerle is cool
Nemerle is cool.It was proved.
Nemerle is notable
Metric
Some metric of using Nemerlein home pet long-term researchproject
uniquation.com formula searchengine
Nemerle is notable
Metric
Two years ago �rst prototype was rewritten from C# toNemerle in 3 days. Nemerle experience before 0.
Code was reduced by 46%.
Last month a new macro library (Nemerle.Peg) was applyed.
Code was reduced by 15%.
Nemerle is notable
Additional materials
Nemerle on google code
Nemerle site
Sources code of examples shown in this presentation