<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I’m currently playing with the mutable array to implement an heap sort sort (from The Art of Computer Programming) and I’m puzzled with an error.</div><div class=""><br class=""></div><div class="">When I code:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier New" class="">toHeap :: Ord a => [a] -> IO [a]</font></div><div class=""><font face="Courier New" class="">toHeap [] = return []</font></div><div class=""><font face="Courier New" class="">toHeap [x] = return [x]</font></div><div class=""><font face="Courier New" class="">toHeap xs = do</font></div><div class=""><font face="Courier New" class=""> arr <- newListArray (1, length xs) xs :: IO (IOArray Int a)</font></div><div class=""><font face="Courier New" class=""> getElems arr</font></div></div><div class=""><br class=""></div><div class="">I’ve got this error:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier New" class="">Could not deduce (a ~ a1)</font></div><div class=""><font face="Courier New" class="">from the context (Ord a)</font></div><div class=""><font face="Courier New" class=""> bound by the type signature for toHeap :: Ord a => [a] -> IO [a]</font></div><div class=""><font face="Courier New" class=""> at /var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:9:11-32</font></div><div class=""><font face="Courier New" class=""> ‘a’ is a rigid type variable bound by</font></div><div class=""><font face="Courier New" class=""> the type signature for toHeap :: Ord a => [a] -> IO [a]</font></div><div class=""><font face="Courier New" class=""> at /var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:9:11</font></div><div class=""><font face="Courier New" class=""> ‘a1’ is a rigid type variable bound by</font></div><div class=""><font face="Courier New" class=""> an expression type signature: IO (IOArray Int a1)</font></div><div class=""><font face="Courier New" class=""> at /var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:14:10</font></div><div class=""><font face="Courier New" class="">Expected type: [a1]</font></div><div class=""><font face="Courier New" class=""> Actual type: [a]</font></div><div class=""><font face="Courier New" class="">Relevant bindings include</font></div><div class=""><font face="Courier New" class=""> xs :: [a]</font></div><div class=""><font face="Courier New" class=""> (bound at /var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:12:8)</font></div><div class=""><font face="Courier New" class=""> toHeap :: [a] -> IO [a]</font></div><div class=""><font face="Courier New" class=""> (bound at /var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:10:1)</font></div><div class=""><font face="Courier New" class="">In the second argument of ‘newListArray’, namely ‘xs’</font></div><div class=""><font face="Courier New" class="">In a stmt of a 'do' block:</font></div><div class=""><font face="Courier New" class=""> arr <- newListArray (1, length xs) xs :: IO (IOArray Int a)</font></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">But with the code below, all work:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier New" class="">toHeap :: Ord a => [a] -> IO [a]</font></div><div class=""><font face="Courier New" class="">toHeap [] = return []</font></div><div class=""><font face="Courier New" class="">toHeap [x] = return [x]</font></div><div class=""><font face="Courier New" class="">toHeap xs = do</font></div><div class=""><font face="Courier New" class=""> arr <- buildArray xs</font></div><div class=""><font face="Courier New" class=""> getElems arr</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">buildArray :: [a] -> IO (IOArray Int a)</font></div><div class=""><font face="Courier New" class="">buildArray xs = newListArray (1, length xs) xs</font></div></div><div class=""><br class=""></div><div class="">What do I miss ?</div><div class=""><br class=""></div><div class="">Thanks.</div><div class=""><br class=""></div><div class="">Chris</div><div class=""><br class=""></div></body></html>