title: Haskell Functions and Mapping
body: <p>This is a homework assignment, and I'm really struggling with the last bit. We are writing "Battleship" in Haskell, and aside from a few general lectures on Functional Languages, we don't have much to go on. No textbook, etc.. I've been referred to LYAH a few times, and there's good stuff there, but it doesn't seem to have suggestions for this particular issue.</p>
  
  <p>For context, I'll put my entire Battleship code up so you can see what definitions I'm referencing later.</p>
  
  <pre><code>--A
  data Row = A | B | C | D | E | F | G | H | I | J deriving (Enum, Ord, Show, Bounded, Eq, Read)
  data Column = One | Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten  deriving (Enum, Ord, Show, Bounded, Eq, Read)
  --B
  data Address = Address Row Column deriving (Show, Read, Eq)
  --C
  data Cell = Cell Address Bool deriving (Show, Read, Eq)
  --D
  data Ship = Ship [Cell] deriving (Show, Eq)
  --E
  data Ships = Ships [Ship] deriving (Show, Eq)
  --F
  toAddress r c = Address (toEnum r) (toEnum c)
  --G
  toRowColumn (Address aRow aColumn) = (fromEnum aRow, fromEnum aColumn)
  --H
  allAddressesA = [ Address row column | row &lt;- [A .. J], column &lt;- [One .. Ten]]
  --I
  allAddressesB = [toAddress row column | row &lt;- [0 .. 9], column &lt;- [0 .. 9]]
  --J
  targetShip (Ship ship) (Address row column)
    | Address == map (\list -&gt; (head Address Bool)) s
  --K
  targetShips [(Ships)] toAddress //TODO
  --L
  isSunk Ship ship
    |ship [] = true
    |otherwise foldl 
  --M
  areSunk [(Ships)] //TODO
  </code></pre>
  
  <p>And now I'll also post the specific assignment descriptions too so there isn't any communication errors with what I need help with:</p>
  
  <blockquote>
    <p>(j) Write a function targetShip that accepts a Ship and a target
    address as its two parameters. If the ship has a cell with the target
    address, that cell is marked sunk. An updated version of the ship is
    returned. If the ship is empty, the empty Ship is returned. (1 map,
    116 characters) </p>
    
    <p>(k) Write a function targetShips that accepts a list
    of Ships and a target address as its two parameters. It attempts to
    sink each ship in the ship list. It returns a list of updated ships.
    If no ships are present, the empty list is returned. (1 map, 86
    characters) </p>
    
    <p>(l) Write a function isSunk that accepts a Ship as its
    parameter. If the ship is the empty ship, return true. Otherwise,
    return true if all cells are marked sunk. (1 fold, 78 characters) </p>
    
    <p>(m) Write a function areSunk that accepts a list of Ships as its
    parameter. If no ships are present, return true. Otherwise, return
    true if all ships are marked sunk. (1 fold, 78 characters)</p>
  </blockquote>
  
  <p>So what my particular struggle here is, is these last 4. Solutions (A - I) I have tested and they work just fine.</p>
  
  <p>We need to know how to reference cell values...the Address and the Bool separately, for starters.</p>
  
  <p>We can't write more functions.</p>
  
  <p>I will assume that you'll want more of an explanation on particular issues, so I'll be monitoring closely. Any hints on where to begin for the last four problems will be greatly appreciated. Thank you in advance...and I'll be headed back to my text editor now and trying to work this out as well.</p>