[Haskell-cafe] Sets, typeclasses and functional dependencies

Stuart Hungerford stuart.hungerford at gmail.com
Sat Jul 31 01:28:30 UTC 2021


Hi Haskellers,

After reading:

https://stackoverflow.com/questions/34790721/where-is-the-set-type-class

https://stackoverflow.com/questions/25191659/why-is-haskell-missing-obvious-typeclasses

https://stackoverflow.com/questions/11508642/haskell-how-can-i-define-a-type-class-for-sets

I can see why Haskell base does not provide typeclasses for sets. I'm
wondering now though if I did create a Set typeclass what it would
look like. There's several approaches using various language
extensions and to me this approach using functional dependencies seems
simpler than the other approaches:

class Setish set a | set -> a where

  empty :: set

  singleton :: a -> set

  -- and so on.

My question is how does the functional dependency in Setish interact
with "extra" types needed for richer set operations like finding the
powerset or taking a cartesian product? Something like:

class Setish set a | set -> a where

  empty :: set

  singleton :: a -> set

  power_set :: set -> ?something

  product :: set -> ?something -> ?something

  -- and so on.

TIA,

Stu


More information about the Haskell-Cafe mailing list