[Haskell-beginners] haskell IO help

Ashley Banks applebiz89 at hotmail.com
Wed May 6 11:04:45 EDT 2009




From: applebiz89 at hotmail.com
To: beginners at haskell.org
Subject: 
Date: Wed, 6 May 2009 13:28:18 +0000








I havent done much IO at all in haskell, only within the function itself.
However I want to get the input from the interface for the function and
havent done this before.

// Say I have this as my data type and list of films
data Film = Film String String Int [String]
-- List of films

testDatabase :: [Film]
testDatabase = [(Film "Casino Royale" "Martin Campbell" 2006 ["Garry",
"Dave", "Zoe"]) ]

// with functions such as:

becomeFan :: String -> String -> [Film] -> [Film]
becomeFan _ _ [] = []
becomeFan filmName fanName ((Film title director year fans):xs) 
| filmName == title = (Film title director year fanName:fans) : xs
| otherwise = (Film title director year fans) : becomeFan filmName fanName
xs

filmsInGivenYear :: Int -> [Film] -> [String]
filmsInGivenYear filmYear films = [ title | (Film title director year fans)
<- films, year == filmYear]

// I want to ask the user what function they want to use, I have this so far

main :: IO()
do putStr "Hi there! what is your name: "
fanName = getLine
do putStr "1 = Insert film, 2 = Become a Fan, 3 = The number of fans of a
film, 4 = Film released in a year: "
input = getLine
read input :: Int
(if input == 1 then main x = insertFilm [] else if input == 2 then main x =
becomeFan [] else if input == 3 then main x = numberOfFans [])

// I thought using the if statement would work, but now I cant think how to
gather the needed input for the function they have chosen?

thanks

apple
Get the New Internet Explore 8 Optimised for MSN. Download Now
_________________________________________________________________
Share your photos with Windows Live Photos – Free.
http://clk.atdmt.com/UKM/go/134665338/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090506/b8fe824e/attachment.htm


More information about the Beginners mailing list