Download - Nemerle is Notable

Transcript
Page 1: Nemerle is Notable

Nemerle is notable

Nemerle is notable

Denis Rystsovtwitter.com/rystsov

[email protected]

2011

Page 2: Nemerle is Notable

Nemerle is notable

Origin

Page 3: Nemerle is Notable

Nemerle is notable

Nemerle Experience

Page 4: Nemerle is Notable

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

Page 5: Nemerle is Notable

Nemerle is notable

Why not try?

Nemerle is almost a superset ofC#, so if you know C# you canuse Nemerle.

Page 6: Nemerle is Notable

Nemerle is notable

Why not try?

By the way, Nemerle's compilercan compile C# code, so youcan try it on exising C# project

Page 7: Nemerle is Notable

Nemerle is notable

Why not try?

Why not try?

Page 8: Nemerle is Notable

Nemerle is notable

Part I - use your C# habits

Part I - use your C# habits

Page 9: Nemerle is Notable

Nemerle is notable

Hello world / C#

Page 10: Nemerle is Notable

Nemerle is notable

Hello world / Nemerle

Page 11: Nemerle is Notable

Nemerle is notable

Extension Methods / C#

Page 12: Nemerle is Notable

Nemerle is notable

Extension Methods / Nemerle

Page 13: Nemerle is Notable

Nemerle is notable

LINQ / C#

Page 14: Nemerle is Notable

Nemerle is notable

LINQ / Nemerle

Page 15: Nemerle is Notable

Nemerle is notable

Object Initialization / C#

Page 16: Nemerle is Notable

Nemerle is notable

Object Initialization / Nemerle

Page 17: Nemerle is Notable

Nemerle is notable

Anonymous Types / C#

Page 18: Nemerle is Notable

Nemerle is notable

Anonymous Types / Nemerle

Page 19: Nemerle is Notable

Nemerle is notable

Yield return / C#

Page 20: Nemerle is Notable

Nemerle is notable

Yield return / Nemerle

Page 21: Nemerle is Notable

Nemerle is notable

Dynamic / C#

Page 22: Nemerle is Notable

Nemerle is notable

Dynamic / Nemerle

Page 23: Nemerle is Notable

Nemerle is notable

Type casting / C#

Page 24: Nemerle is Notable

Nemerle is notable

Type casting / Nemerle

Page 25: Nemerle is Notable

Nemerle is notable

Try..Catch / C#

Page 26: Nemerle is Notable

Nemerle is notable

Try..Catch / Nemerle

Page 27: Nemerle is Notable

Nemerle is notable

Partial / C#

Page 28: Nemerle is Notable

Nemerle is notable

Partial / Nemerle

Page 29: Nemerle is Notable

Nemerle is notable

Arrays / C#

Page 30: Nemerle is Notable

Nemerle is notable

Arrays / Nemerle

Page 31: Nemerle is Notable

Nemerle is notable

Attention! Wild dinosaur!

Page 32: Nemerle is Notable

Nemerle is notable

Goto?

What is about..

GOTO?unlike C# Nemerle doesn't support it, but..

Page 33: Nemerle is Notable

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

Page 34: Nemerle is Notable

Nemerle is notable

Named code blocks

Page 35: Nemerle is Notable

Nemerle is notable

Beyond C#

After this short intro you canwrite apps in Nemerle in C#style.

But Nemerle goes far beyond it

Page 36: Nemerle is Notable

Nemerle is notable

Desired C# features

Itsupportsthe most desiredfeatures of the nextversions of C# right now

Page 37: Nemerle is Notable

Nemerle is notable

Part II - desired C# features

Part II - desired C# features

Page 38: Nemerle is Notable

Nemerle is notable

Object initializers with events

Page 39: Nemerle is Notable

Nemerle is notable

Painless XML generation

Page 40: Nemerle is Notable

Nemerle is notable

INotifyPropertyChanged language support

Page 41: Nemerle is Notable

Nemerle is notable

`Safe navigation' operator

Page 42: Nemerle is Notable

Nemerle is notable

Design by contract

Page 43: Nemerle is Notable

Nemerle is notable

Sequence initialization (list comprehension)

Page 44: Nemerle is Notable

Nemerle is notable

Yield from lambda

Page 45: Nemerle is Notable

Nemerle is notable

Improved lazy support

Page 46: Nemerle is Notable

Nemerle is notable

Part III � functional programming

Part III � functionalprogramming (FP)

Page 47: Nemerle is Notable

Nemerle is notable

What is FP?

Typical signs of FPMonadsType inferencePattern matchingAlgebraic data typesBuilt-in tuple supportLocal (nested) functions

Page 48: Nemerle is Notable

Nemerle is notable

Nemerle supports FP

Nemerle supports it all

Page 49: Nemerle is Notable

Nemerle is notable

Type inference

Page 50: Nemerle is Notable

Nemerle is notable

Local functions

Page 51: Nemerle is Notable

Nemerle is notable

Built-in tuple support

Page 52: Nemerle is Notable

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.

Page 53: Nemerle is Notable

Nemerle is notable

Monads

Consequently Nemerle supportsthe upcoming C# 5async/await feature right nowamong the other monads.

Page 54: Nemerle is Notable

Nemerle is notable

Example of easy composition of two async methods

Page 55: Nemerle is Notable

Nemerle is notable

Algebraic data types

Short intro toalgebraic data types

Page 56: Nemerle is Notable

Nemerle is notable

Algebraic data types

Let's learn ADT by example

Suppose we need to work withexpressions like

a + sin(b)

Page 57: Nemerle is Notable

Nemerle is notable

Algebraic data type

Of couse we need trees

Page 58: Nemerle is Notable

Nemerle is notable

OOP approach to trees (class hierarchy)

Page 59: Nemerle is Notable

Nemerle is notable

FP approach to trees (ADT - algebraic data type)

Page 60: Nemerle is Notable

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?

Page 61: Nemerle is Notable

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.

Page 62: Nemerle is Notable

Nemerle is notable

Pretty Printing of `Tree' typed object

Page 63: Nemerle is Notable

Nemerle is notable

Algebraic data type � OOP vs. FP

OOP

72 SLoC (pretty printing withvisitor pattern)

FP

25 SLoC (pretty printing withpattern matching)

Page 64: Nemerle is Notable

Nemerle is notable

Variant is OOP enabled algebraic data type

Page 65: Nemerle is Notable

Nemerle is notable

Pattern matching goes beyond disassembling

Pattern matching can be nested.

Page 66: Nemerle is Notable

Nemerle is notable

Almost all features are macros

Nemerle seems to be complex,but. . .

Page 67: Nemerle is Notable

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.

Page 68: Nemerle is Notable

Nemerle is notable

Almost all Nemerle features are macros

You've already meet macros inthis presentation, they are. . .

Page 69: Nemerle is Notable

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

Page 70: Nemerle is Notable

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.

Page 71: Nemerle is Notable

Nemerle is notable

Nemerle is cool

Nemerle is cool.It was proved.

Page 72: Nemerle is Notable

Nemerle is notable

Metric

Some metric of using Nemerlein home pet long-term researchproject

uniquation.com formula searchengine

Page 73: Nemerle is Notable

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%.

Page 74: Nemerle is Notable

Nemerle is notable

Additional materials

Nemerle on google code

Nemerle site

Sources code of examples shown in this presentation


Top Related