[Haskell-cafe] Getting started - help

Magnus Therning magnus at therning.org
Thu Apr 30 08:01:32 EDT 2009

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

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?


Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe

More information about the Haskell-Cafe mailing list