How can I represent 4x4 map in haskell

Hi can you please tell me how can I represent 4x4 map in haskell.Should I show it as a list of lines and each line to be a list of char or I am mistaken? Thanks in advance! -- View this message in context: http://www.nabble.com/How-can-I-represent-4x4-map-in-haskell-tp16396273p1639... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

iliali16 wrote:
Hi can you please tell me how can I represent 4x4 map in haskell.Should I show it as a list of lines and each line to be a list of char or I am mistaken? Thanks in advance!
Sure this is no homework? If it is, please first consult: http://www.haskell.org/haskellwiki/Homework_help -- Dr. Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:voigt@tcs.inf.tu-dresden.de

This is a little off-topic, but perhaps we can have some discussion of that Wiki page? The Haskell community has a reputation of being helpful and welcoming to newcomers. I'm having a hard time reconciling that with this wiki page. In particular. 1. The tone is generally threatening, as in: if you step over the line, you could be reported for cheating, so don't ask for too much help. 2. There's a general RTFM attitude. 3. There's a link to Eric Raymond's insulting article at the end, which goes on to inform people that we don't care about them, we are only here for our personal daily fix of mental challenge, and if they can't meet that then they've got no business wasting our time. Let me be clear: I am not arguing that we should do people's homework for them. But I am arguing for changing the tone of the response. I'd have been rather put off if that wiki page had been my first introduction to the Haskell community. -- Chris Smith

Hi Chris,
The Haskell community has a reputation of being helpful and welcoming to newcomers. I'm having a hard time reconciling that with this wiki page. In particular.
For those who want to follow along, its this one: http://haskell.org/haskellwiki/Homework_help I agree. That page is pretty nasty. It looks like the person summarised Eric Raymond's article, which is also pretty nasty. A rewrite would be very good!
Let me be clear: I am not arguing that we should do people's homework for them. But I am arguing for changing the tone of the response. I'd have been rather put off if that wiki page had been my first introduction to the Haskell community.
Yes. I think that we should suggest people ask homework questions to homework authors, as they are based equipped to answer the questions using the techniques and tools the students have been taught. But politely, and saying why they benefit doing it the right way. Thanks Neil

iliali16 wrote:
Hi can you please tell me how can I represent 4x4 map in haskell.Should I show it as a list of lines and each line to be a list of char or I am mistaken? Thanks in advance!
What do you mean by a 4x4 map? Maybe I'm missing something obvious, but there are several different meanings for "map", and I don't see which one you mean. -- Chris Smith

I mean board but I found the solution to my problem don't worry I really don't want someone to do my Project since I won't learn from that and I really want to learn since that's what is important at the end of the day. Thanks to all that people who understood what I mean and advised me, thanks again! Chris Smith wrote:
iliali16 wrote:
Hi can you please tell me how can I represent 4x4 map in haskell.Should I show it as a list of lines and each line to be a list of char or I am mistaken? Thanks in advance!
What do you mean by a 4x4 map? Maybe I'm missing something obvious, but there are several different meanings for "map", and I don't see which one you mean.
-- Chris Smith
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/How-can-I-represent-4x4-map-in-haskell-tp16396273p1640... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Just to let you know that that is not a homework just for one function representing the map. It is my project wich I subdivided into peaces but since I am not that new to haskell I am not sure if I am on the right track so that is my code till now: type Line = [Char] type Board = [Line] so my question is if this is ok to represent a map. If yes I will try to write the function which makes it 4 x 4 myself. What I jsut need as an answer is Yes or No. Just to let you know is that I am trying to build the Wumpus World iliali16 wrote:
Hi can you please tell me how can I represent 4x4 map in haskell.Should I show it as a list of lines and each line to be a list of char or I am mistaken? Thanks in advance!
-- View this message in context: http://www.nabble.com/How-can-I-represent-4x4-map-in-haskell-tp16396273p1639... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

iliali16 wrote:
Just to let you know that that is not a homework just for one function representing the map. It is my project wich I subdivided into peaces but since I am not that new to haskell I am not sure if I am on the right track so that is my code till now:
type Line = [Char] type Board = [Line]
so my question is if this is ok to represent a map.
That certainly is one way to represent a map. For example, for any b::Board you will be able to access elements via b !! i !! j for some i,j from 0 to 3. Whether it is the best choice of representation for your application very much depends on what you are going to do with it. For example, which kind of operations on boards you are going to need. Just to mention an alternative: if it is important for your application that you always have exactly 4x4 maps, and you do not want to ensure this invariant "by hand", then you could use something along the lines of:
type Quadruple a = (a,a,a,a) type Line = Quadruple Char type Board = Quadruple Line
Then, of course, you have to write your own "accessors" to get an element at position i,j. (But there are several ways, differing in their level of complication, of making this more generic, rather than inventing your own Quadruple. Probably they are overkill for your goal.) Ciao, Janis. -- Dr. Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:voigt@tcs.inf.tu-dresden.de

iliali16 wrote:
type Line = [Char] type Board = [Line]
so my question is if this is ok to represent a map. If yes I will try to write the function which makes it 4 x 4 myself. What I jsut need as an answer is Yes or No. Just to let you know is that I am trying to build the Wumpus World
A list of lists of cells is a possible representation for a two-dimensional array, yes. for bigger maps, there may be a performance problem, but for such a small world, it should be fine. You may consider using an array, e.g. with import Data.Array type Board = Array (Int, Int) Char Boards will be indexed by coordinate tuples. Another point: maybe you should use an algebraic data type instead of Char to represent the individual cells? e.g. data Cell = Wumpus | Trap | Gold | Nothing type Board = [[Cell]] Be aware of the Wumpus! Tillmann

On 1 Apr 2008, at 3:51 am, iliali16 wrote:
so my question is if this is ok to represent a map. If yes I will try to write the function which makes it 4 x 4 myself. What I jsut need as an answer is Yes or No. Just to let you know is that I am trying to build the Wumpus World
What you should know is that there is no rule that the Wumpus World has to be 4 x 4. Quoting http://web.inf.tu-dresden.de/~mit/LRAPP/wumpus/wumpus.htm "The size of the grid may vary for different scenarios." You are tacitly assuming that if you want to know what's where in the wumpus world you have to store an *image* of that world. But this is not so. The wumpus may be dead, in which case we don't care where it is, or it may be in some specific location: wumpus :: Maybe Location The gold may have been grabbed, in which case we know where it is without looking (we have it), or it may be in some specific place: gold :: Maybe Location In some versions of the wumpus world, there may be more than one piece of gold. In that case, gold :: [Location] There is some number of pits. There might be none. All we really want to know is whether a particular square is a pit or not. is_pit :: Location -> Bool It's not clear to me whether the gold or the wumpus might be in a pit. Since it's deadly to enter a pit anyway, we don't really care. The gold and the wumpus might well be in the same cell. So we can do this: type Location = (Int, Int) data Wumpus_World = Wumpus_World { bounds :: Location, wumpus :: Maybe Location, gold :: Maybe Location, is_pit :: Location -> Bool } initial_world = Wumpus_World { bounds = (4,4), wumpus = Just (3,3), gold = Just (3,3), is_pit = \loc -> case loc of (2,1) -> True (4,3) -> True _ -> False } -- I just made this one up holds :: Eq a => Maybe a -> a -> Bool holds (Just x) y = x == y holds (Nothing) _ = False has_wumpus, has_gold :: Wumpus_World -> Location -> Bool has_wumpus world location = wumpus world `holds` location has_gold world location = wumpus world `holds` location There are lots of other ways to do this, and whether this is a good one depends on what you need to do with it. It might be better to have has_wumpus :: Location -> Bool has_gold :: Location -> Bool as the field members directly, for example. One thing that is right about it is that it doesn't build in any specific idea of the size of the world. Another good thing is that it postpones the decision about how to tell where the pits are. But of course there are two maps: the complete map of how the world really is, which the world simulator has to have, and the "agent's" partial map recording what it has seen so far. They might have similar representations, or they might not. It's a really good idea to write as much of the code as you can so that it doesn't know what the map representation is.
participants (6)
-
Chris Smith
-
iliali16
-
Janis Voigtlaender
-
Neil Mitchell
-
Richard A. O'Keefe
-
Tillmann Rendel