Thread Solved

Join Date: Apr 2009
Posts: 7
Reputation: applebiz89 is an unknown quantity at this point 
Solved Threads: 0
applebiz89 applebiz89 is offline Offline
Newbie Poster

Haskell IO help

 
0
  #1
May 6th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 139
Reputation: thoughtcoder is on a distinguished road 
Solved Threads: 12
thoughtcoder thoughtcoder is offline Offline
Junior Poster

Re: Haskell IO help

 
0
  #2
May 7th, 2009
It's hard to understand what you're trying to do with all that unindented code.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 7
Reputation: applebiz89 is an unknown quantity at this point 
Solved Threads: 0
applebiz89 applebiz89 is offline Offline
Newbie Poster

Re: Haskell IO help

 
0
  #3
May 7th, 2009
In my main function, I want to ask the user what they would like to do 'become fan' for example, then with their choice initiate the function and ask for the appropriate input for that function. This is the code below:

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 [])

Say they choose film in a given year function function:

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

I need to ask the user what filmYear they want to insert. But i need to do this from the main function...I chose to do an if statement to choose what function they want, but i dont know where to go from there?


so once it is determined they want to use this function i want to ask them 'what film year: ' and use that for the 'Int' in the filmInGivenYear function
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 139
Reputation: thoughtcoder is on a distinguished road 
Solved Threads: 12
thoughtcoder thoughtcoder is offline Offline
Junior Poster

Re: Haskell IO help

 
0
  #4
May 7th, 2009
You could use code tags in your messages.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Legacy and Other Languages Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC