1

Here is my code

quadtreeToPic QNode x y w avg Q4(q1 q2 q3 q4) = array ((0,0) (w-1,w-1)) (concat (map quadtreeToPic [q1, q2, q3, q4])) 

Basically, a Quadtree is x y w avg QChildren where QChildren is qither Q0 or Q4 Quadtree Quadtree Quadtree Quadtree.

When I do what I tried above, I get this error

Quadtree.hs:13:34: error: Parse error in pattern: q1
   |
13 | quadtreeToPic QNode x y w avg Q4(q1 q2 q3 q4) = array ((0,0) (w-1,w-1)) (concat (map quadtreeToPic [q1, q2, q3, q4])) 
   |                                  ^^^^^^^^^^^

Why is this?

1
  • 2
    You need to add brackets around the Q4 data constructor, so quadtreeToPic QNode x y w avg (Q4 q1 q2 q3 q4) = ... Commented Jul 30, 2019 at 17:41

1 Answer 1

3

The Q4 dataconstructor and the parameters are a single parameter, here, so you need to add brackets including the Q4 data constructor. For example:

quadtreeToPic QNode x y w avg (Q4 q1 q2 q3 q4) = ...

Note that you can use concatMap :: (a -> [b]) -> [a] -> [b] here instead of concat (map ...):

... concatMap quadtreeToPic [q1, q2, q3, q4]
Sign up to request clarification or add additional context in comments.

4 Comments

I get the error Quadtree.hs:13:85: error: • Couldn't match type ‘Array (Int, Int) Word8’ with ‘[((Int, Int), Word8)]’ Expected type: [[((Int, Int), Word8)]] Actual type: [Array (Int, Int) Word8] • In the first argument of ‘concat’, namely ‘(map quadtreeToPic [q1, q2, q3, q4])’ In the second argument of ‘array’, namely ‘(concat (map quadtreeToPic [q1, q2, q3, q4]))’ In the expression: array ((0, 0) (w - 1, w - 1)) (concat (map quadtreeToPic [q1, q2, q3, q4]))
after I make this fix. Any idea why?
@user2719875: that's a type error: your quadtreeToPic is supposed to return [((Int, Int), Word8)]]s, but it returns [Array (Int, Int) Word8]?
it looks like it's a different question altogether. I asked it here, if you can help: stackoverflow.com/questions/57277522/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.