[Haskell-cafe] typeclass constraints?

William Yager will.yager at gmail.com
Sat Nov 5 19:43:22 UTC 2016


You probably want

:set -XExistentialQuantification
data Test = forall a . Show a => Test String a

Under the hood, this works by storing the vtable for the "Show" typeclass
for whatever object you're putting in the Test. You could explicitly unpack
this like

data TestY = forall a . Test String a (a -> String)

Cheers,
Will

On Sat, Nov 5, 2016 at 2:09 PM, Gregory Guthrie <guthrie at mum.edu> wrote:

>
>    data (Show a) => ATest =  Test (String, a)
>
> but that also fails, although it does give the right idea; all tests have
> a common structure, with a second value in the Show typeclass.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161105/d6710314/attachment.html>


More information about the Haskell-Cafe mailing list