<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div dir="auto">Thanks very much for that clear reply Michael.<br>
<br>
I don't have an application in mind specifically, the example
function groupConsecutive just came up in another message and set
me wondering: if I have a function to work on types of class A,
but types that are instances of both class A and class B are
problematic, is there a way to distinguish the cases? As you say,
it's probably not class A that I want my function to work over,
but instead my own type class.<br>
<br>
Graham<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On 15 Jan 2017 14:09, "Michael Orlitzky"
<<a href="mailto:michael@orlitzky.com">michael@orlitzky.com</a>>
wrote:<br type="attribution">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">On
01/14/2017 02:35 AM, Graham Gill wrote:<br>
><br>
> Do I need two different versions of f, one for Bounded a
and one for<br>
> non-Bounded a? Is there a more elegant way to take care
of this problem?<br>
> I don't know much about all of the type magic available
in GHC.<br>
><br>
<br>
You probably want your own typeclass instead of Enum, even if
it means<br>
generating a bunch of very boring instances of it for the
types you want<br>
"f" to work on.<br>
<br>
The fact that "pred" should throw a runtime error on
"minBound" is a<br>
documented fact of the Enum typeclass, and you should stay far
far away<br>
from such things in your own code. Besides that, there's a
weird<br>
interaction between the semantic meaning of Enum and Bounded.
For<br>
example, here's a perfectly valid enumeration of boolean
values:<br>
<br>
True, False, True, False, ...<br>
<br>
In your case it would be fine to have (pred False) == True,
but instead<br>
you get a runtime error thanks to the Bounded instance. So
being Bounded<br>
rules out some otherwise valid (and fine for your purposes)
Enum instances.<br>
<br>
Your "f" should also work on a singleton type:<br>
<br>
ghci> data Foo = Foo deriving (Eq,Show)<br>
ghci> instance Enum Foo where toEnum _ = Foo; fromEnum _
= 0;<br>
ghci> groupConsecutive [Foo,Foo,Foo,Foo]<br>
[[Foo,Foo,Foo,Foo]]<br>
<br>
But any Bounded instance for Foo would mess that up.
Basically, the<br>
pre-existing Enum instances aren't exactly what you want.<br>
<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a
href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners"
rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</blockquote>
</div>
</div>
</body>
</html>