Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.15 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.org
  2.  
  3. open System
  4.  
  5. //czesc I
  6. //wywalic do osobnego pliku (aby uzyc namespace)
  7.  
  8. [<AbstractClass>]
  9. type Zwierze() =
  10.     let mutable nazwa : string = "zwierze"
  11.  
  12.     let mutable dataUr : DateTime = new DateTime(0L)
  13.    
  14.  
  15.     abstract member Odglos : string
  16.  
  17.     abstract member Opis : string
  18.            
  19.  
  20. type Lew (str) =
  21.     inherit Zwierze()
  22.     let mutable umaszczenie : string = str
  23.  
  24.     override this.Odglos = "dzwieki lwa"
  25.  
  26.     override this.Opis = "lew"
  27.  
  28.  
  29.  
  30. type Slon (dl) =
  31.     inherit Zwierze()
  32.     let mutable dlugoscTraby: float = dl
  33.  
  34.     override this.Odglos = "dzwieki slonia"
  35.  
  36.     override this.Opis = "slon"
  37.  
  38.  
  39. type LewIndyjski (str2) =
  40.     inherit Lew(str2)
  41.     override this.Opis = "lew indyjski"  
  42.  
  43.  
  44.  
  45. //czesc II
  46.  
  47.  
  48. //zad 1
  49. let sum liczby = List.fold (fun a x -> a+x) 0 liczby
  50.  
  51. //zad2
  52. let przeksztalc liczby = List.map(fun x -> x.ToString()) liczby
  53.  
  54.  
  55. //zad3
  56. let tryParseToFloat(s:string) : float option =
  57.     match System.Double.TryParse(s) with
  58.          | true, x -> Some(x)
  59.          | _ -> None
  60.  
  61. let parseToFloats liczby : float option list = List.map (fun x -> tryParseToFloat(x)) liczby
  62.  
  63. //zad 4
  64. let zip liczby = List.zip liczby (parseToFloats liczby)
  65.  
  66.  
  67. //zad 5
  68.  
  69. let maxx liczby =
  70.     match liczby with
  71.     | head::teil ->
  72.         List.fold (fun a x -> if a<x then x else a) head teil
  73.     | _ -> 0
  74.  
  75. let minn liczby =
  76.     match liczby with
  77.     |head::teil ->
  78.         List.fold (fun a x -> if a>x then x else a) head teil
  79.     |_ -> 0
  80.  
  81.  
  82.  
  83. [<EntryPoint>]
  84. let main argv =
  85.  
  86.     let myClass = new LewIndyjski("Lew")
  87.  
  88.     let mySlon = new Slon(170.0)
  89.  
  90.     printfn "%A %A" myClass.Odglos myClass.Opis
  91.  
  92.     printfn "%A %A" mySlon.Odglos mySlon.Opis
  93.  
  94.     printfn "Suma = %i" (sum [1;3;4])
  95.  
  96.     printfn "Przeksztalcenie = %A" (przeksztalc [1;3;4])
  97.  
  98.     printfn "Przeksztalcenie2 = %A" (parseToFloats ["4";"1,4";"4.5"])    
  99.  
  100.     printfn "Przeksztalcenie3 = %A" (zip ["4";"1,4";"4.5"])  
  101.  
  102.     printfn "maksymalna = %A" (maxx [1;3;4;10;1;42;2])  
  103.  
  104.     printfn "minimalna = %A" (minn [1;3;4;10;1;42;2])  
  105.  
  106.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement