Hello,<br><br>I get an error message on the code below with GHC. I can't figure out how to get rid of the error. I'd appreciate suggestions on how to fix this. (BTW, the code may look overly combersome because I stripped out anything unnecessary to demonstrate the error.)<br>
<br><span style="font-family: courier new,monospace;">{-# OPTIONS_GHC </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> -fglasgow-exts </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> -fbreak-on-exception </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> -fallow-undecidable-instances</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#-}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import qualified Prelude</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">import Prelude </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import Data.Array.IArray</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class Sequence seq where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> slength :: (seq e) -> Int</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> snull :: (seq e) -> Bool</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> shead :: (seq e) -> e</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> stail :: (seq e) -> (seq e)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance Sequence [] where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> slength = length</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> snull = null</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> shead = head</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> stail = tail</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class From_seq t where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> from_seq :: (Sequence seq) => (seq e) -> (t e)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance From_seq [] where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> from_seq seq </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> | snull seq = []</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> | otherwise = (shead seq) : (from_seq (stail seq))</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">from_seq' seq</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> | snull seq = (listArray (0,-1) [])</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> | otherwise = listArray (0,fromIntegral (slength seq) -1) (from_seq seq)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{-</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">When I uncomment this out, I get the error messages:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Error.hs:41:19:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Could not deduce (IArray a e)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> from the context (From_seq (a i),</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Ix i,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Num i,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> IArray a e1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Sequence seq)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> arising from a use of `from_seq'' at Error.hs:41:19-31</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance (Ix i, Num i, IArray a e) => From_seq (a i) where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> from_seq seq = from_seq' seq</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">-}</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br>When I load the module above, I can evaluate the folloing in GHCI<br><br><span style="font-family: courier new,monospace;">*Main> from_seq' [0..5] :: Array Int Double</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">array (0,5) [(0,0.0),(1,1.0),(2,2.0),(3,3.0),(4,4.0),(5,5.0)]</span><br style="font-family: courier new,monospace;"><br>But, I'd like to do this with the From_seq class. If anyone has suggestions, I'd be grateful. <br>
<br>Thanks,<br><br>Jeff<br>