[Haskell-cafe] Is there a type class for boring types?

Oliver Charles ollie at ocharles.org.uk
Tue Feb 2 18:05:46 UTC 2016


Seems a bit of an ad hoc class, but maybe

class (Bounded a, Eq a) => Singular a where
  singular :: a

With the constraint that singular = maxBound = minBound. Not going to let
you write an instance for (->) though, but maybe there are other ways to
get that with a different property.

On Tue, Feb 2, 2016 at 5:42 PM David Feuer <david.feuer at gmail.com> wrote:

> Or, alternatively, some common class that lets me express that a type is
> boring (i.e., inhabited by precisely one fully-defined value)? lens has
> Settable, whose law ensures the type involved has a boring representation
> (in the sense of representable functor), but is there a more fundamental
> way?
>
> class Boring x where
>   inhabitant :: x
> instance Boring () where
>   inhabitant = ()
> instance Boring (Proxy a) where
>   inhabitant = Proxy
> instance Boring y => Boring (x -> y) where
>   inhabitant = const inhabitant
> instance (Boring x, Boring y) => Boring (x, y) where
>   inhabitant = (inhabitant, inhabitant)
> instance Boring x => Boring (Const x y) where
>   inhabitant = Const inhabitant
> instance Boring x => Boring (Identity x) where
>   inhabitant = Identity inhabitant
> ...
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160202/ffc2a18e/attachment.html>


More information about the Haskell-Cafe mailing list