Note that there are some explanatory texts on larger screens.

plurals
  1. POmanual Instance Show definition causes Stack Space Overflow
    text
    copied!<p>When I write manually a simple show instance for the PhisicalCell datatype, the program consumes all the space. When deriving his own version of Show, this doesn't happen. Why?</p> <p>here is a stripped-down version of the code I'm writing:</p> <pre><code>import Data.Array type Dimensions = (Int, Int) type Position = (Int, Int) data PipeType = Vertical | Horizontal | UpLeft | UpRight | DownLeft | DownRight deriving (Show) data PhisicalCell = AirCell | PipeCell PipeType | DeathCell | RecipientCell Object -- deriving (Show) SEE THE PROBLEM BELOW data Object = Pipe { pipeType :: PipeType -- tipo di tubo , position :: Position -- posizione del tubo , movable :: Bool -- se posso muoverlo } | Bowl { position :: Position -- posizione dell'angolo in alto a sinistra , dimensions :: Dimensions -- dimensioni (orizzontale, verticale) , waterMax :: Int -- quanta acqua puo' contenere al massimo , waterStart :: Int -- con quanta acqua parte , hatch :: Maybe Position -- un eventuale casella di sbocco , sourceIn :: [Position] -- posti da cui l'acqua entra , movable :: Bool -- se posso muoverlo } | Death deriving (Show) data Level = Level Dimensions [Object] type LevelTable = Array Dimensions PhisicalCell -- HERE IS THE PROBLEM -- instance Show PhisicalCell where show AirCell = " " show (PipeCell _) = "P" show DeathCell = "X" show (RecipientCell _) = "U" both :: (a -&gt; b) -&gt; (a,a) -&gt; (b,b) both f (a,b) = (f a, f b) levelTable :: Level -&gt; LevelTable levelTable (Level dim _) = initial where initial = array ((0,0), both (+1) dim) $ [((x,y), AirCell) | x &lt;- [1..fst dim], y &lt;- [1..snd dim] ] ++ [((x,y), DeathCell) | x &lt;- [0..fst dim + 1], y &lt;- [0, snd dim + 1]] ++ [((x,y), DeathCell) | x &lt;- [0, fst dim + 1], y &lt;- [0..snd dim + 1]] main = print $ levelTable (Level (8,12) []) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload