Selaa lähdekoodia

Merge branch 'exo'

Exercice with pattern matching
DricomDragon 5 vuotta sitten
vanhempi
commit
ec8b3d9f6a
2 muutettua tiedostoa jossa 17 lisäystä ja 0 poistoa
  1. 13 0
      geometry.hs
  2. 4 0
      logic.hs

+ 13 - 0
geometry.hs

@@ -0,0 +1,13 @@
+data Point = Point Float Float
+
+data Shape = Singularity Point | Circle Float Point | Square Point Point
+
+distance p1 p2 = 
+	let (Point a b) = p1 in
+		let (Point c d) = p2 in
+			sqrt ((a - c) * (a - c) + (b - d) * (b - d))
+
+perimeter sh = case sh of
+	Singularity _ -> 0.0
+	Circle r _ -> 3.14 * 2 * r
+	Square (Point a b) (Point c d) -> 2 * abs (a - c) + 2 * abs (b - d)

+ 4 - 0
logic.hs

@@ -0,0 +1,4 @@
+myAnd b1 b2 = 
+	case (b1, b2) of
+	(True, True) -> True
+	(_, _) -> False