1 / 10

F-Sharp (F#)

F-Sharp (F#). Eine multiparadigmatische Sprache. Merkmale von F#. Multiparadigmatisch .NET-Sprache Skalierbar und effizient Als Forschungsprojekt von Microsoft Research entwickelt und 2002 publiziert Starke syntaktische Ähnlichkeit mit OCaml. Einsatzgebiete von F#.

Télécharger la présentation

F-Sharp (F#)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. DiscriminatedUnions open System //wegen Convert.ToString() typeTree<'a> = | Leaf | Branch of Tree<'a> * 'a * Tree<'a> with memberthis.Print = matchthiswith | 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) = letmutablex_pos = x letmutabley_pos = y new () = Shape( 0.0, 0.0) memberthis.X = x_pos; memberthis.Y = y_pos; memberthis.MovedXdY = x_pos <- x_pos + dX y_pos <- y_pos + dY typeIDrawable = abstractmember Draw : unit -> unit type Circle( x: float, y : float, r : float) = inherit Shape(x, y) letmutableradius = r interfaceIDrawablewith memberthis.Draw() = printfn"Draw Circle(%f, %f)"this.Xthis.Y

  7. Pattern matching letSayHelloname lang = matchname, 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!" letsign = functionletsign x= | 0 ->0matchxwith | x when x > 0 -> 1 ==| 0 -> 0 | _ -> -1| xwhenx > 0 -> 1 | _ -> -1

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

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

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

More Related