[Haskell-cafe] Getting started - help

applebiz89 applebiz89 at hotmail.com
Thu Apr 30 08:07:57 EDT 2009

firstly no it isnt homework. I havent run it through the compiler because I
know it won't compile as I havent finished the function as you can see. I
was just asking for guidance on how to understand what to do. So now I know
to put the fan's into a list, which I have done. So then I can just add the
fan's directly to the list of fans if the name of the film matches the
desired film to be a fan of.

Magnus Therning wrote:
> First off, is this homework?
> You really ought to start with passing your code to GHCi, or the
> compiler, to see whether it's accepted before sending questions to the
> mailing list.  At least if you are interested in getting constructive
> replies.
> On Thu, Apr 30, 2009 at 12:33 PM, applebiz89 <applebiz89 at hotmail.com>
> wrote:
>> What I need to do is build a type of database. Firstly have a few
>> questions,
>> whether what I have done it right...and how to do something else.
>> This is my algebraic type for the database (correct me if its wrong)
>> data Film = Film String String Int String
>> with this as the data.
>> testDatabase :: [Film]
>> testDatabase = [("Casino Royale", "Martin Campbell",2006, "Garry, Dave,
>> Zoe")]
>> the last set of strings are the fans to the film. I want to be able to
>> add a
>> new fan, but not sure how to specifically insert it to there
> If the fans is a "set of strings" why not represent them as a list of
> strings (`[String]`)?
>> this is what I have so far:
>> becomeFan :: String -> String -> [Film] -> [Film]
>> becomeFan = do putStr "Which film are you a fan of:  "
>>            filmTitle <- getLine
>>            do putStr "What is your name: "
>>            fanName <- getLine
>>            (if filmTitle == filmName then fanName : [Film])
> The type is wrong, you need to do this in the `IO` monad.
> A more serious issue is that I don't understand at all what you intend
> this code to do.  It isn't valid Haskell, but I think that instead of
> battling Haskell you should, at this point, go back to your algorithm.
>  Answer the question, given your type, what steps are needed to add a
> fan to a single film?  Then you can progress to answering, what steps
> are needed to add a fan to a specific film in a list of films?
> /M
> -- 
> Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
> magnus@therning.org          Jabber: magnus@therning.org
> http://therning.org/magnus         identi.ca|twitter: magthe
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

View this message in context: http://www.nabble.com/Getting-started---help-tp23314466p23314963.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list