Patrick,

> -- Class with functional dependency
> class QUEUE_SPEC_CLASS2 a q | q -> a where
>    newC2 :: q a -- ??
>    sizeC2  :: q a -> Int
>    restC2  :: q a -> Maybe (q a)
>    insertC2 :: q a -> a -> q a

The above is a reasonable type class definition for what you seem to intend.

> -- Without committing to some concrete representation such as list I do not 
> know how to specify constructor for insertC2 ?? =  ??
>    insertC2  newC2 a = newC2 -- wrong
>    isEmptyC2  :: q a -> Bool
>    isEmptyC2 newC2  = True
> --   isEmptyC2 (insertC2 newC2 a) = False wrong

Correct me if I'm wrong, but what I understand you want to do here is
specify axioms on the behaviour of the above interface methods,
similar to how the well-known |Monad| class specifies for example "m
>>= return === m".  You seem to want for example an axiom saying

  isEmptyC2 newC2 === True

and similar for possible other equations. With such axioms you don't
need access to actual constructors and you don't want access to them
because concrete implementations may use a different representation
that does not use such constructors. Anyway, in current Haskell, such
type class axioms can not be formally specified or proven but they are
typically formulated as part of the documentation of a type class and
implementations of the type class are required to satisfy them but
this is not automatically verified.

Dominique

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to