Use cases of empty type classes

Hi everyone, I have one question. What are current use cases of type classes with no methods? I saw early uses in type-level programming (e.g. HList [1]). In the OO world, interfaces with no methods are called marker interfaces -- their use cases range from things that could be done with datatype generic programming in Haskell (e.g. serialization) to metadata annotations (e.g. RandomAccess [2]). Regards, Tomas Tauber [1] http://okmij.org/ftp/Haskell/HList-ext.pdf [2] https://docs.oracle.com/javase/8/docs/api/java/util/RandomAccess.html

I have two use cases for them
In fay-jquery there’s an empty Selectable class that has instances for all elements that can be passed to the jQuery function, there is no need for methods since we in the background just pass the object along, but we want to make sure we don’t pass something nonsensical.
In a rest API serving JSON you need ToJSON and FromJSON instances for each type, but since internal APIs may also use JSON it’s possible that you by accident pass a type that isn’t versioned and supposed to be included in the public API. There I can have an empty PublicApiType class with instances for all public types to give a type error if I pass something internal by mistake.
/Adam Bergmark
On Tue 08 Mar 2016 at 07:10 Tomas Tauber
<
mailto:Tomas Tauber
wrote:
Hi everyone, I have one question. What are current use cases of type classes with no methods? I saw early uses in type-level programming (e.g. HList [1]). In the OO world, interfaces with no methods are called marker interfaces -- their use cases range from things that could be done with datatype generic programming in Haskell (e.g. serialization) to metadata annotations (e.g. RandomAccess [2]). Regards, Tomas Tauber [1] http://okmij.org/ftp/Haskell/HList-ext.pdf [2] https://docs.oracle.com/javase/8/docs/api/java/util/RandomAccess.html _______________________________________________ Haskell-Cafe mailing list mailto:Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

You can use them to claim something about multiple type classes at once,
with some advantages over using ConstraintKinds for the same purpose:
https://www.reddit.com/r/haskell/comments/49em92/haskells_typeclasses_we_can...
On Tue, Mar 8, 2016 at 6:36 AM Adam Bergmark
I have two use cases for them
- In fay-jquery there’s an empty Selectable class that has instances for all elements that can be passed to the jQuery function, there is no need for methods since we in the background just pass the object along, but we want to make sure we don’t pass something nonsensical. - In a rest API serving JSON you need ToJSON and FromJSON instances for each type, but since internal APIs may also use JSON it’s possible that you by accident pass a type that isn’t versioned and supposed to be included in the public API. There I can have an empty PublicApiType class with instances for all public types to give a type error if I pass something internal by mistake.
/Adam Bergmark
On Tue 08 Mar 2016 at 07:10 Tomas Tauber
> wrote: Hi everyone,
I have one question. What are current use cases of type classes with no methods?
I saw early uses in type-level programming (e.g. HList [1]). In the OO world, interfaces with no methods are called marker interfaces -- their use cases range from things that could be done with datatype generic programming in Haskell (e.g. serialization) to metadata annotations (e.g. RandomAccess [2]).
Regards,
Tomas Tauber
[1] http://okmij.org/ftp/Haskell/HList-ext.pdf [2] https://docs.oracle.com/javase/8/docs/api/java/util/RandomAccess.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Thanks everybody. I found this helpful (:
вт, 8 мар. 2016 г. в 19:58, Alex Rozenshteyn
You can use them to claim something about multiple type classes at once, with some advantages over using ConstraintKinds for the same purpose: https://www.reddit.com/r/haskell/comments/49em92/haskells_typeclasses_we_can...
On Tue, Mar 8, 2016 at 6:36 AM Adam Bergmark
wrote: I have two use cases for them
- In fay-jquery there’s an empty Selectable class that has instances for all elements that can be passed to the jQuery function, there is no need for methods since we in the background just pass the object along, but we want to make sure we don’t pass something nonsensical. - In a rest API serving JSON you need ToJSON and FromJSON instances for each type, but since internal APIs may also use JSON it’s possible that you by accident pass a type that isn’t versioned and supposed to be included in the public API. There I can have an empty PublicApiType class with instances for all public types to give a type error if I pass something internal by mistake.
/Adam Bergmark
On Tue 08 Mar 2016 at 07:10 Tomas Tauber
> wrote: Hi everyone,
I have one question. What are current use cases of type classes with no methods?
I saw early uses in type-level programming (e.g. HList [1]). In the OO world, interfaces with no methods are called marker interfaces -- their use cases range from things that could be done with datatype generic programming in Haskell (e.g. serialization) to metadata annotations (e.g. RandomAccess [2]).
Regards,
Tomas Tauber
[1] http://okmij.org/ftp/Haskell/HList-ext.pdf [2] https://docs.oracle.com/javase/8/docs/api/java/util/RandomAccess.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Hi,
Simon Marlow's paper[1] introduces a type class named `Exception` which has
no methods.
Here `Exception` is defined as a synonym for `Typeable` and `Show`:
class (Typeable a, Show a) => Exception a
[1] "An Extensible Dynamically-Typed Hierarchy of Exceptions
http://community.haskell.org/~simonmar/papers/ext-exceptions.pdf
On Wed, Mar 9, 2016 at 12:48 AM, Geraldus
Thanks everybody. I found this helpful (:
вт, 8 мар. 2016 г. в 19:58, Alex Rozenshteyn
: You can use them to claim something about multiple type classes at once, with some advantages over using ConstraintKinds for the same purpose: https://www.reddit.com/r/haskell/comments/49em92/haskells_typeclasses_we_can...
On Tue, Mar 8, 2016 at 6:36 AM Adam Bergmark
wrote: I have two use cases for them
- In fay-jquery there’s an empty Selectable class that has instances for all elements that can be passed to the jQuery function, there is no need for methods since we in the background just pass the object along, but we want to make sure we don’t pass something nonsensical. - In a rest API serving JSON you need ToJSON and FromJSON instances for each type, but since internal APIs may also use JSON it’s possible that you by accident pass a type that isn’t versioned and supposed to be included in the public API. There I can have an empty PublicApiType class with instances for all public types to give a type error if I pass something internal by mistake.
/Adam Bergmark
On Tue 08 Mar 2016 at 07:10 Tomas Tauber
> wrote: Hi everyone,
I have one question. What are current use cases of type classes with no methods?
I saw early uses in type-level programming (e.g. HList [1]). In the OO world, interfaces with no methods are called marker interfaces -- their use cases range from things that could be done with datatype generic programming in Haskell (e.g. serialization) to metadata annotations (e.g. RandomAccess [2]).
Regards,
Tomas Tauber
[1] http://okmij.org/ftp/Haskell/HList-ext.pdf [2] https://docs.oracle.com/javase/8/docs/api/java/util/RandomAccess.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

One empty typeclass I use often not only has no methods, but also has no members. class Void This is useful in type families that return Constraint, when you want to say this constraint is "unsatisfiable". I suppose returning something like "True ~ False" would also suffice, but isn't as pretty. On Monday, March 7, 2016 at 10:10:48 PM UTC-8, Tomas Tauber wrote:
Hi everyone,
I have one question. What are current use cases of type classes with no methods?
I saw early uses in type-level programming (e.g. HList [1]). In the OO world, interfaces with no methods are called marker interfaces -- their use cases range from things that could be done with datatype generic programming in Haskell (e.g. serialization) to metadata annotations (e.g. RandomAccess [2]).
Regards,
Tomas Tauber
[1] http://okmij.org/ftp/Haskell/HList-ext.pdf [2] https://docs.oracle.com/javase/8/docs/api/java/util/RandomAccess.html _______________________________________________ Haskell-Cafe mailing list Haskel...@haskell.org javascript: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

One nice trick for this is to return an equality involving type level strings:
"Cannot satisfy FooBarBaz" ~ ()
In GHC 8, there will also be a type level function TypeError for this
purpose [1].
Erik
[1] https://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html#cust...
On 10 March 2016 at 19:42, Mitchell Rosen
One empty typeclass I use often not only has no methods, but also has no members.
class Void
This is useful in type families that return Constraint, when you want to say this constraint is "unsatisfiable". I suppose returning something like "True ~ False" would also suffice, but isn't as pretty.
On Monday, March 7, 2016 at 10:10:48 PM UTC-8, Tomas Tauber wrote:
Hi everyone,
I have one question. What are current use cases of type classes with no methods?
I saw early uses in type-level programming (e.g. HList [1]). In the OO world, interfaces with no methods are called marker interfaces -- their use cases range from things that could be done with datatype generic programming in Haskell (e.g. serialization) to metadata annotations (e.g. RandomAccess [2]).
Regards,
Tomas Tauber
[1] http://okmij.org/ftp/Haskell/HList-ext.pdf [2] https://docs.oracle.com/javase/8/docs/api/java/util/RandomAccess.html _______________________________________________ Haskell-Cafe mailing list Haskel...@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

The constraints package currently uses
class Any => Bottom where
no :: Dict a
It should probably actually use
no :: a
but that's a minor point.
There are two ideas:
1. The class constraint Any is a stuck type family, so it's utterly
impossible to create an instance of Bottom. Thus any entailment c :-
Bottom implies that c is unsatisfiable.
2. There's an entailment
bottom :: Bottom :- c
bottom = Sub no
On Thu, Mar 10, 2016 at 1:42 PM, Mitchell Rosen
One empty typeclass I use often not only has no methods, but also has no members.
class Void
This is useful in type families that return Constraint, when you want to say this constraint is "unsatisfiable". I suppose returning something like "True ~ False" would also suffice, but isn't as pretty.
On Monday, March 7, 2016 at 10:10:48 PM UTC-8, Tomas Tauber wrote:
Hi everyone,
I have one question. What are current use cases of type classes with no methods?
I saw early uses in type-level programming (e.g. HList [1]). In the OO world, interfaces with no methods are called marker interfaces -- their use cases range from things that could be done with datatype generic programming in Haskell (e.g. serialization) to metadata annotations (e.g. RandomAccess [2]).
Regards,
Tomas Tauber
[1] http://okmij.org/ftp/Haskell/HList-ext.pdf [2] https://docs.oracle.com/javase/8/docs/api/java/util/RandomAccess.html _______________________________________________ Haskell-Cafe mailing list Haskel...@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
participants (8)
-
Adam Bergmark
-
Alex Rozenshteyn
-
David Feuer
-
Erik Hesselink
-
Geraldus
-
KwangYul Seo
-
Mitchell Rosen
-
Tomas Tauber