Code for Bob

From HaskellWiki
Revision as of 15:16, 6 February 2021 by Gwern (talk | contribs) (Reverted edits by Tomjaguarpaw (talk) to last revision by Quale)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
#!/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