Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

F-Sharp (F#) Eine multiparadigmatische Sprache. Merkmale von F# Multiparadigmatisch.NET-Sprache Skalierbar und effizient Als Forschungsprojekt von Microsoft.

Ähnliche Präsentationen


Präsentation zum Thema: "F-Sharp (F#) Eine multiparadigmatische Sprache. Merkmale von F# Multiparadigmatisch.NET-Sprache Skalierbar und effizient Als Forschungsprojekt von Microsoft."—  Präsentation transkript:

1 F-Sharp (F#) Eine multiparadigmatische Sprache

2 Merkmale von F# Multiparadigmatisch.NET-Sprache Skalierbar und effizient Als Forschungsprojekt von Microsoft Research entwickelt und 2002 publiziert Starke syntaktische Ähnlichkeit mit OCaml

3 Einsatzgebiete von F# Sicherheitskritische Aufgaben Datenverarbeitung Beschreibung komplexer physikalischer, mathematischer Zusammenhänge

4 Unterschiede zu Haskell Haskell ist eine rein funktionale Sprache Kein deklarieren von Funktionen in F# Rekursive Funktionen müssen in F# mit rec markiert sein In F# muss alles mit let definiert werden F# bietet Units of Measure F# hat direkten Zugriff zum.NET-Framework

5 Discriminated Unions open System //wegen Convert.ToString() type Tree = | Leaf | Branch of Tree * 'a * Tree with member this.Print = match this with | Leaf -> printfn "Blatt" | Branch(_, key, _) -> printfn "Knoten mit dem Wert %s" (Convert.ToString(key)) let tree1 = Branch(Leaf, 10, Leaf) tree1.Print

6 Klassen, Vererbung, Schnittstellen type Shape(x : float, y : float) = let mutable x_pos = x let mutable y_pos = y new () = Shape( 0.0, 0.0) member this.X = x_pos; member this.Y = y_pos; member this.Move dX dY = x_pos <- x_pos + dX y_pos <- y_pos + dY type IDrawable = abstract member Draw : unit -> unit type Circle( x: float, y : float, r : float) = inherit Shape(x, y) let mutable radius = r interface IDrawable with member this.Draw() = printfn "Draw Circle(%f, %f)" this.X this.Y

7 Pattern matching let SayHello name lang = match name, lang with | "Frank", _ -> printfn "Hi, Frank" | _, "ger" -> printfn "Hallo, %s. Wie geht's?" name | _, "eng" -> printfn "Hello, %s." name | "Mike", _ | "Alie", _ -> printfn "Na du!" | _, _ -> printfn "Hey!" let sign = functionlet sign x = | 0 -> 0match x with | x when x > 0 -> 1 == | 0-> 0 | _ -> -1| x when x > 0-> 1 | _->-1

8 Funktionen höherer Ordnung let list = [1..30] let double_list = List.map (fun x -> x * 2) list let filter_list = List.filter (fun x -> (x % 2) = 0) list let zip_list = List.zip double_list filter_list //Fehler: Listen sind nicht gleich lang let rec myZip f list1 list2 = match list1, list2 with | [], [] | _, [] | [], _ -> [] | x :: xss, y :: yss -> (x, y, (f x y)) :: myZip f xss yss

9 Lazy Evaluation let rec fibu = function | 0 -> 0 | 1 -> 1 | x -> fibu (x - 1) + fibu (x - 2) let x = Lazy.Create(fun _ -> printfn "Werte x aus..."; fibu 20) let y = Lazy.Create(fun _ -> printfn "Werte y aus..."; x.Value + 10)

10 Quellen Programming F# - A Comprehensive Guide for Writing Simple Code to Solve Complex Problems, Chris Smith http://msdn.microsoft.com/de-de/magazine/cc164244.aspx#S1 http://msdn.microsoft.com/de-de/library/vstudio/dd233181.aspx


Herunterladen ppt "F-Sharp (F#) Eine multiparadigmatische Sprache. Merkmale von F# Multiparadigmatisch.NET-Sprache Skalierbar und effizient Als Forschungsprojekt von Microsoft."

Ähnliche Präsentationen


Google-Anzeigen