Difference between revisions of "Code for Bob"

From HaskellWiki
Jump to navigation Jump to search
(+cat)
(Deleted old dead page)
Line 1: Line 1:
[[Category:Code]]
 
<haskell>
 
#!/usr/local/bin/runhugs
 
import "/home/ralf/hudak_soe/HUnit-1.0/HUnit"
 
newtype Lover a = Lover {loverDiary :: (Name,a)}
 
deriving Show
 
type Name = String
 
 
createLover :: Name -> a -> (Lover a)
 
createLover name times = Lover (name,times)
 
 
chainAffairs :: Num a => Lover a -> Lover a -> Lover a
 
chainAffairs (Lover (names, oldtimes)) (Lover (newlady, newtimes)) =
 
Lover ((newlady ++ names), (oldtimes + newtimes))
 
 
startAffairWith :: Num a => Name -> Lover b -> Lover a
 
startAffairWith name (Lover (names,times)) = Lover (name,0)
 
 
jenny = startAffairWith "Jenny "
 
luisa = startAffairWith "Luisa "
 
antonia = startAffairWith "Antonia "
 
 
bob = createLover "Paula " 5
 
 
oneMoreTime :: Num a => Lover a -> Lover a
 
oneMoreTime (Lover (name, times)) = Lover (name, times+1)
 
 
test1 = TestCase (assertEqual "this test" ("Lover{loverDiary=(\"Paula \",5)}")
 
(show bob))
 
--test1 = TestCase (assertEqual "this test" () ())
 
tests = TestList [TestLabel "test1" test1]
 
 
main = do runTestTT tests
 
do
 
let
 
bob' = (oneMoreTime bob)
 
test2 = TestCase (assertEqual
 
"this test" ("Lover{loverDiary=(\"Paula \",6)}")
 
(show bob'))
 
tests2 = TestList [TestLabel "test2" test2]
 
in
 
runTestTT tests2
 
</haskell>
 

Revision as of 10:45, 6 February 2021