scala, haskell and fantom programming language

9
Scala, Haskell and Fantom Programming Language Raymark D. Dulce (200712952) January 01, 2011

Upload: christie-morota

Post on 02-Apr-2015

503 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: scala, haskell and fantom programming language

Scala, Haskell and Fantom ProgrammingLanguage

Raymark D. Dulce (200712952)

January 01, 2011

Page 2: scala, haskell and fantom programming language

Scala Programming Language

What is Scala?

Scala is a multi-paradigm programming language designed to integratefeatures of object-oriented programming and functional programming. Thename Scala stands for ”scalable language”, signifying that it is designed togrow with the demands of its users.

Scala is a general purpose programming language designed to expresscommon programming patterns in a concise, elegant, and type-safe way. Itsmoothly integrates features of object-oriented and functional languages, en-abling Java and other programmers to be more productive.

History of Scala

The design of Scala started in 2001 at the cole Polytechnique F d ralede Lausanne (EPFL) by Martin Odersky, following on from work on Funnel,a programming language combining ideas from functional programming andPetri nets. Odersky had previously worked on Generic Java and javac, Sun’sJava compiler.

Scala was released late 2003 / early 2004 on the Java platform, and onthe .NET platform in June 2004. A second version of the language, v2.0, wasreleased in March 2006. As of November 2010, the latest release is version2.8.1.

Platforms and License

Scala runs on the Java platform(Java Virtual Machine) and is compatiblewith existing Java programs. It also runs on Java Platform, Micro EditionConnected Limited Device Configuration. Scala has the same compilationmodel as Java and C-sharp, so Scala code can call Java libraries (or .NETlibraries in the .NET implementation).

Scala’s operational characteristics are the same as Java’s. The Scalacompiler generates byte code that is nearly identical to that generated bythe Java compiler. In fact, Scala code can be decompiled to readable Javacode, with the exception of certain constructor operations.

To the JVM, Scala code and Java code are indistinguishable. The onlydifference is a single extra runtime library, scala-library.jar. The Scala soft-ware distribution, including compiler and libraries, is released under a BSDlicense.

1

Page 3: scala, haskell and fantom programming language

Seamless integration with JAVA

Existing Java code and programmer skills are fully re-usable. Scala pro-grams run on the Java VM, are byte code compatible with Java so you canmake full use of existing Java libraries or existing application code. You cancall Scala from Java and you can call Java from Scala, the integration isseamless.

Moreover, you will be at home with familiar development tools, Eclipse,NetBeans or Intellij for example, all of which support Scala.

Scala is object-oriented

Scala is a pure object-oriented language in the sense that every value isan object. Types and behavior of objects are described by classes and traits.Classes are extended by subclassing and a flexible mixin-based compositionmechanism as a clean replacement for multiple inheritance.

Scala is functional

Scala is also a functional language in the sense that every function isa value. Scala provides a lightweight syntax for defining anonymous func-tions, it supports higher-order functions, it allows functions to be nested, andsupports currying. Scala’s case classes and its built-in support for patternmatching model algebraic types.

Scala is statically typed

Scala is equipped with an expressive type system that enforces staticallythat abstractions are used in a safe and coherent manner. In particular, thetype system supports:

• generic classes

• variance annotations

• upper and lower type bounds

• inner classes and abstract types as object members

2

Page 4: scala, haskell and fantom programming language

• compound types

• explicitly typed self references

• views, and

• polymorphic methods.

Scala is extensible

In practice, the development of domain-specific applications often requiresdomain-specific language extensions. Scala provides a unique combinationof language mechanisms that make it easy to smoothly add new languageconstructs in form of libraries:

• any method may be used as an infix or postfix operator, and closuresare constructed automatically depending on the expected type (targettyping).

• A joint use of both features facilitates the definition of new statementswithout extending the syntax and without using macro-like meta pro-gramming facilities.

The Hello World Program

object HelloWorld

{

def main(args: Array[String])

{

println("Hello, world!")

}

}

3

Page 5: scala, haskell and fantom programming language

Haskell Programming Language

What is Haskell?

Haskell is an advanced purely-functional programming language. Anopen-source product of more than twenty years of cutting-edge research, itallows rapid development of robust, concise, correct software.

Haskell is a computer programming language. In particular, it is a poly-morphically statically typed, lazy, purely functional language, quite differentfrom most other programming languages. The language is named for HaskellBrooks Curry, whose work in mathematical logic serves as a foundation forfunctional languages.

Haskell is based on the lambda calculus, hence the lambda we use as alogo. It is a standardized, general-purpose purely functional programminglanguage, with non-strict semantics and strong static typing.

History of Haskell

Haskell 1.0

The first version of Haskell (Haskell 1.0) was defined in 1990.

Haskell 98

In late 1997, the series culminated in Haskell 98, intended to specify a sta-ble, minimal, portable version of the language and an accompanying standardlibrary for teaching, and as a base for future extensions. In February 1999,the Haskell 98 language standard was originally published as The Haskell98 Report. In January 2003, a revised version was published as Haskell 98Language and Libraries: The Revised Report.

Haskell Prime

In early 2006, the process of defining a successor to the Haskell 98 stan-dard, informally named Haskell’, was begun. This is an ongoing incrementalprocess to revise the language definition, producing a new revision once peryear. The first revision, named Haskell 2010, was announced in Nov. 2009.

4

Page 6: scala, haskell and fantom programming language

Haskell 2010

Haskell 2010 adds the Foreign Function Interface (FFI) to Haskell, allow-ing for bindings to other programming languages, fixes some syntax issues(changes in the formal grammar) and bans so-called n-plus-k-patterns, thatis, definitions of the form fak (n+1) = (n+1) * fak n are no longer allowed.It introduces the Language-Pragma-Syntax-Extension which allows for des-ignating a haskell source as Haskell 2010 or requiring certain Extensions tothe Haskell Language. The names of the extensions introduced in Haskell2010 are DoAndIfThenElse, HierarchicalModules, EmptyDataDeclarations,FixityResolution, ForeignFunctionInterface, LineCommentSyntax, Pattern-Guards, RelaxedDependencyAnalysis, LanguagePragma, NoNPlusKPatterns.

Why use Haskell?

Haskell offers you:

• Substantially increased programmer productivity

• Shorter, clearer, and more maintainable code.

• Fewer errors, higher reliability.

• A smaller semantic gap between the programmer and the language.

• Shorter lead times.

The Hello World Program

"Hello, World!"

OR

putStrLn "Hello World"

OR

main = putStrLn "Hello, World!"

5

Page 7: scala, haskell and fantom programming language

Fantom Programming Language

What is Fantom?

Fantom is a general purpose object-oriented programming language thatruns on the JRE, .NET CLR, and Javascript. The language supports func-tional programming through closures and concurrency through the Actormodel.

Fantom takes a middle of the road approach to its type system, blend-ing together aspects of both static and dynamic typing. Like C-sharp andJava, Fantom uses a curly brace syntax. Fantom is designed as a practicalprogramming language to make it easy and fun to get real work done.

Fantom is an exciting new language that targets the Java VM and theCLR. It borrows it’s Syntax from Java but also adds many features andsyntactic sugar created or borrowed from .NET,Groovy,Python,Erlang etc.It is familiar to a Java / .Net programmer but is much less painful to use (noboilerplate).

History of Fantom

The original name of the Fantom programming language was Fan, namedafter the neighborhood where the creators live in Richmond, Virginia. Aftergaining some popularity, members of the community raised concerns aboutthe searchability of the name. In November 2009, the name of the projectwas officially changed from Fan to Fantom.

Typing

Fantom’s type system is simple by design. All variables are staticallytyped, as they are in C-sharp and Java. Fantom rejects generic types due totheir complexity, but it does have a set of built-in generic types: List, Map,and Func. Fantom can also take on the feel of a dynamically typed languagethrough dynamic calls and automatic downcasting. Fantom has an easy touse reflection API and metaprogramming capabilities.

6

Page 8: scala, haskell and fantom programming language

Pods

In Fantom, the unit of deployment is called a pod. Pods take on the role ofnamespaces, packages, and modules. They are stored as .pod files, which arezip files containing the FCode (the Fantom bytecode), the documentation,and resource files necessary to run the pod. A pod can define any number oftypes for use in other libraries and applications. A pod name fully qualifiesa type name. For example, fwt::Widget is distinct from webapp::Widget. Ifa pod contains a type named Main, then it can be executed on the commandline with:fan ¡podName¿ The Fantom build system can package a set of Podsinto a Jar archive through build::JarDist.

Portability

Fantom is created to write software that can seamlessly run on both theJava VM and the .NET CLR. The reality is that many software organiza-tions are committed to one or the other of these platforms. Even dynamiclanguages like Python and Ruby are getting hosted on one of these VMs.

Familiar Syntax

Java and C-sharp programmers will feel at home with Fantom’s evolu-tionary syntax.

Elegant APIs

Quite obsessive about providing all the key features required for a stan-dard library, but with much less surface area than the APIs found in Java or.NET.

Object Oriented

Fantom follows the .NET model of value types. The three special typesBool, Int, and Float are value types which are implemented as primitives inJava and value types in .NET. These types have all the same performancecharacteristics of using boolean, long, and double in Java or C-sharp. UnlikeJava these types cleanly subclass from Obj to create a unified class hier-archy. The compiler automatically implements boxing and unboxing whennecessary.

7

Page 9: scala, haskell and fantom programming language

Funtional Programming

Fantom was designed from the ground up to support functions as firstclass objects. Closures are a key feature of the language, and all the APIsare written to use functions and closures where appropriate. Functions andclosures are baked in.

Declarative Programming

Fantom incorporates declarative programming right into the language.Fantom supports a literal syntax for lists, maps, ranges, uris, and durations.Fantom also includes a text serialization syntax which is human readableand writable. The serialization syntax is a clean subset of the programminglanguage - so you can paste a serialization file right into your source code asan expression.

Concurrency

Fantom tackles concurrency using a couple techniques:

• Immutability is built into the language (thread safe classes)

• Static fields must be immutable (no shared mutable state)

• Actors model for message passing (Erlang style concurrency)

The Hello World Program

class HelloWorld

{

static Void main()

{

echo("Hello, World!")

}

}

8