Question on how to export my function

Queue.hs

module Queue (Queue(..)) where 
    Import Prelude hiding (head.tail) 
    class Queue q where
    empty    :: q a
    isEmpty  :: q a-> Bool 
    snoc     :: q a-> a->q a 
    head     ::  q a -> a 
    tail     ::  q a-> qa

BatchedQueue.hs

module BatchedQueue (BatchedQueue(BQ,check)) where
        Import Prelude hiding (head.tail) 
        Import Queue 
        data BatchedQueuea = BQ [a] [a] 
        check [] r = BQ (reverse r) [] 
        check f r  = BQ f r 
        instance QueueBatchedQueue where 
        empty = BQ [] [] 
        isEmpty (BQ f r) = null f 
        snoc (BQ f i) x = check f (x: r) 
        head (BQ [] _) = error "empty queue" 
        head (BQ (x : f)  t) = x 
        tail (BQ [] _) = error "empty queue"
        tail (BQ (x: f) r) = check f r

main.hs

module Main where
import Queue
import BatchedQueue
import Data.Typeable
main :: IO()
main = putStrLn("hello world")

Above are three source files I try to compile,but after I typed at current working directory,

ghc -o main.out main.hs

I got an error

[2 of 3] Compiling BatchedQueue     ( BatchedQueue.hs, BatchedQueue.o )

BatchedQueue.hs:1:21:
    The export item ‘BatchedQueue(BQ, check)’
    attempts to export constructors or class methods that are not visible here

How do I solved this,I searched google,but really have no idea why.Thanks.

shouldn’t BatchedQueue(BQ,check) be BatchedQueue(BQ) ,check?

3 Likes

You saved me,sir!Thank you so much.

Also, a little formatting advice: it is very unusual to indent all the contents of a module. And, maybe you didn’t do this because of posting here, but putting spaces in between different definitions would make your code much more readable. And your spacing is weird to. To illustrate all these, I would write Queue.hs as:

module Queue (Queue (..)) where 

import Prelude hiding (head, tail) 

class Queue q where
    empty   :: q a
    isEmpty :: q a -> Bool 
    snoc    :: q a -> a -> q a 
    head    :: q a -> a 
    tail    :: q a -> q a
2 Likes