Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type ulam = int*int
- exception DzieleniePrzezZero
- type xy = { x:int; y:int }
- let rec NWD = function
- | (0, n) -> n
- | (m, n) -> NWD(n % m, m)
- let skroc (l,m) =
- let znak = if l*m<0 then -1 else 1
- let al = abs l
- let am = abs m
- let d = NWD(al,am)
- in (znak * (al / d), am / d)
- let ( ++ ) (a, b) (c, d) =
- if(b=0 || d=0)
- then raise DzieleniePrzezZero
- else (skroc (a*d + b*c, b*d))
- let ( +++ ) (a:xy) (b:xy) =
- if(a.y=0 || b.y=0)
- then raise DzieleniePrzezZero
- else (skroc (a.x*b.y + a.y*b.x, a.y*b.y))
- let ( -- ) (a, b) (c, d) = (a*d - b*c, b*d)
- let ( ** ) (a, b) (c, d) = (a*c, b*d)
- let ( /./ ) (a, b) (c, d) = (a,b) ** (d,c)
- let ( == ) (a, b) (c, d) = (a*d = b*c)
- let wynik = 1./2. + 2./3. * 3./4.
- let wynik2 = (1,2)++(2,3)**(3,4)
- let naString (l, m) =
- let znak = if l*m<0 then "-" else ""
- let al = abs l
- let am = abs m
- let d = NWD(al, am)
- let calkowita = al/am
- in znak + if(calkowita<>0) then System.Convert.ToString(calkowita) else ""
- + if((al%am)<>0) then ( " " + (System.Convert.ToString((al%am) / d))
- + "/" + (System.Convert.ToString(am / d))) else ""
- let q1 = (-2, 3);
- let q2 = (5, -10);
- let q3 = q1++q2
- let q4 = q2**q3
- let q5 = q4/./q3
- type samochod = {marka:string; rocznik:int; pojemnosc:float}
- let siena = { marka = "FIAT"; rocznik = 1997; pojemnosc = 1586.0}
- let maluch = { marka = "FIAT"; rocznik = 1987; pojemnosc = 648.0}
- let malolitrazowy (x:samochod) = x.pojemnosc < 900.0;
- type osoba = {imie : string; urodzony : int; adres : string}
- let kier1 = {imie="Adam"; adres = "Rzeszów"; urodzony = 1960};
- let kier2 = {imie="Olek"; adres = "Jasło"; urodzony = 1986};
- let starszy(k1:osoba,k2:osoba) = k1.urodzony < k2.urodzony
- type rej = {pojazd : samochod; posiadacz: osoba}
- let sam1:rej = {pojazd = siena; posiadacz = kier1};
- let sam2:rej = {pojazd = maluch; posiadacz = kier2};
- let wiekszapojemnosc (s1: rej, s2 :rej) =
- s1.pojazd.pojemnosc > s2.pojazd.pojemnosc;
- let aa={x = -2; y = 3}
- let bb={x = 5; y= -10}
- //6.
- let rec doPotegi (a, b) n =
- if(n=0) then (1,1) else ((a,b)**(doPotegi (a,b)(n-1)))
- [<EntryPoint>]
- let main argv =
- printfn "%A" q3
- printfn "%A" q4
- printfn "%A" q5
- printfn "%A" (starszy (kier1,kier2))
- printfn "%A" sam1.pojazd.rocznik
- printfn "%A" (wiekszapojemnosc (sam1,sam2))
- printfn "%A" (q1++q2)
- printfn "%A" (aa+++bb)
- printfn "%A" (naString (1,3))
- printfn "%A" (doPotegi (1,2) 4)
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement