Say I have a queue implementation in a file and wanted to import it to work in a main file. I'm having trouble figuring out how to properly do so without getting a constructor error.
Say I have this in one file Queue1.hs
module Queue1 (Queue, mtq, ismt, addq, remq) where
data Queue a = Queue1 [a] deriving (Show)
-- multiple methods defined . . .
Then in my main file say I have:
import Queue1
And wanted to do this, which adds a list to the beginning of the Queue:
addq :: [a] -> Queue a -> Queue a
addq xs q = undefined
How exactly would I create the function so that I can use the Queue methods defined in another file?
I have created the following variations with no success:
adds xs (Queue q) = (xs:q)
error: Not in scope: data constructor ‘Queue’
|
13 | adds xs (Queue q) = (xs:q)
I also tried defining another Queue in the file which didn't work:
data Queue a = Queue3 [a] deriving Show
adds :: [a] -> Queue a -> Queue as
adds xs (Queue3 q) = Queue3(xs:q)
error:
Ambiguous occurrence ‘Queue’
It could refer to
either ‘Queue1.Queue’,
imported from ‘Queue1’ at lab3.hs:4:1-13
(and originally defined at Queue1.hs:17:1-41)
or ‘Main.Queue’, defined at lab3.hs:9:1
Can anyone point to what I'm doing wrong?