ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Intro.hs
.
exchangeRate = 9.7365
toEUR sek = sek / echangeRate
toSEK eur = eur * exchangeRate
:load Intro.hs
[1 of 1] Compiling Main ( Intro.hs, interpreted )
Ok, modules loaded: Main.
toEur 85
8.730036460740513
toSEK 9
87.6285
toSEK (toEUR 85)
85.0
:reload
to reload the file(s) after changes.
:l
and :r
as
abbreviations for :load
and :reload
.
prop_exchange s = toSEK (toEUR s) == s
prop_
are properties we expect to hold.
import Test.QuickCheck
:r
[1 of 1] Compiling Main ( Intro.hs, interpreted )
Ok, modules loaded: Main.
quickCheck prop_exchange
*** Failed! Falsifiable (after 5 tests and 1078 shrinks):
5.0e-324
x ~== y = x-y < 1e-10
prop_exchange s = toSEK (toEUR s) ~== s
:r
[1 of 1] Compiling Main ( Intro.hs, interpreted )
Ok, modules loaded: Main.
quickCheck prop_exchange
+++ OK, passed 100 tests.
4 ~== 3
False
3 ~== 4
True
x ~== y = abs (x-y) < 1e-10
-- | Compute the absolute value of x absolute x | x >= 0 = 0 absolute x | x < 0 = -x
absolute x | x >= 0 = 0 absolute x | x < 0 = -x
absolute x | x >= 0 = 0 | x < 0 = -x
absolute x = if x < 0 then -x else x
x^n
power x 0 = 1 power x n | n > 0 = x * power x (n-1)
power 3 2
3 * power 3 (2-1)
3 * power 3 1
3 * (3 * power 3 (1-1))
3 * (3 * power 3 0)
3 * (3 * 1)
3 * 3
9
power x n
intersect 0 = 0 intersect n | n > 0 = intersect (n-1) + n - 1
:type
to ask for the type of an expression.
:browse
to see the type of everything in the current module.
:t toEUR
toEUR :: Double -> Double
:browse
exchangeRate :: Double
toEUR :: Double -> Double
toSEK :: Double -> Double
prop_exchange :: Double -> Bool
(~==) :: (Ord a, Fractional a) => a -> a -> Bool
power :: (Ord t1, Num t1, Num t) => t -> t1 -> t
Double
power 2 1.5
power :: Integer -> Integer -> Integer power n 0 = 1 power n k | k>0 = n * power n (k-1)
abs 3-5 abs (3-5)
{ ... ; ... ; }
a = 3; b = 4; c = 5