Petr P | 21 Dec 13:38 2012
Picon

MPTC or functional dependencies?

Dear Haskellers,

I'm working on a small library for representing semigroup (or monoid) actions on a set <http://hackage.haskell.org/package/semigroups-actions>.
The MultiParamTypeClasses extension seems to be best suited for the task, as a group can act on many sets, and a set can be acted on by different groups:

    -- | Represents an action of semigroup <at> g <at> to set <at> a <at> .
    --
    -- Laws: <at> 'Endo' . 'act' <at> must be a homomorphism of semigroups.
    class Semigroup g => SemigroupAct g a where
        act :: g -> (a -> a)

But soon I realized that with MPTC the compiler has problems inferring types and I had to explicitly specify types when using `act` in many places. Because it seems that in most cases a set will have only a single group acting on it, I was thinking about using FDs:

    class Semigroup g => SemigroupAct g a | a -> g where

But on the other hand, this can limit the generality of the type class. I cannot decide which one I should choose.

What would you suggest? According to your experience, would you choose plain MPTC or FD?

Best regards,
Petr Pudlak

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Kim-Ee Yeoh | 21 Dec 14:09 2012

Re: MPTC or functional dependencies?

Petr,

Your subject header is misleading: FDs don't make sense without MPTCs. 

As you acknowledge at the end, what you're ultimately asking is: to FD or not to FD. 

Note also, the contemporary debate has shifted to TFs (type families) vs FDs.


-- Kim-Ee


On Fri, Dec 21, 2012 at 7:38 PM, Petr P <petr.mvd <at> gmail.com> wrote:
Dear Haskellers,

I'm working on a small library for representing semigroup (or monoid) actions on a set <http://hackage.haskell.org/package/semigroups-actions>.
The MultiParamTypeClasses extension seems to be best suited for the task, as a group can act on many sets, and a set can be acted on by different groups:

    -- | Represents an action of semigroup <at> g <at> to set <at> a <at> .
    --
    -- Laws: <at> 'Endo' . 'act' <at> must be a homomorphism of semigroups.
    class Semigroup g => SemigroupAct g a where
        act :: g -> (a -> a)

But soon I realized that with MPTC the compiler has problems inferring types and I had to explicitly specify types when using `act` in many places. Because it seems that in most cases a set will have only a single group acting on it, I was thinking about using FDs:

    class Semigroup g => SemigroupAct g a | a -> g where

But on the other hand, this can limit the generality of the type class. I cannot decide which one I should choose.

What would you suggest? According to your experience, would you choose plain MPTC or FD?

Best regards,
Petr Pudlak


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Petr P | 21 Dec 14:16 2012
Picon

Re: MPTC or functional dependencies?

  Hi Kim-Ee,

you're right, it's a bit misleading.

I thought about TFs too, personally I mostly prefer them over FDs, but I'd like the library available for as many compilers as possible. 'semigroups' is just Haskell 98 and I'd like to keep the requirements similarly low.

  Best regards,
  Petr Pudlak


2012/12/21 Kim-Ee Yeoh <ky3 <at> atamo.com>
Petr,

Your subject header is misleading: FDs don't make sense without MPTCs. 

As you acknowledge at the end, what you're ultimately asking is: to FD or not to FD. 

Note also, the contemporary debate has shifted to TFs (type families) vs FDs.


-- Kim-Ee


On Fri, Dec 21, 2012 at 7:38 PM, Petr P <petr.mvd <at> gmail.com> wrote:
Dear Haskellers,

I'm working on a small library for representing semigroup (or monoid) actions on a set <http://hackage.haskell.org/package/semigroups-actions>.
The MultiParamTypeClasses extension seems to be best suited for the task, as a group can act on many sets, and a set can be acted on by different groups:

    -- | Represents an action of semigroup <at> g <at> to set <at> a <at> .
    --
    -- Laws: <at> 'Endo' . 'act' <at> must be a homomorphism of semigroups.
    class Semigroup g => SemigroupAct g a where
        act :: g -> (a -> a)

But soon I realized that with MPTC the compiler has problems inferring types and I had to explicitly specify types when using `act` in many places. Because it seems that in most cases a set will have only a single group acting on it, I was thinking about using FDs:

    class Semigroup g => SemigroupAct g a | a -> g where

But on the other hand, this can limit the generality of the type class. I cannot decide which one I should choose.

What would you suggest? According to your experience, would you choose plain MPTC or FD?

Best regards,
Petr Pudlak


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Roman Cheplyaka | 21 Dec 14:35 2012

Re: MPTC or functional dependencies?

* Petr P <petr.mvd <at> gmail.com> [2012-12-21 13:38:21+0100]
> Dear Haskellers,
> 
> I'm working on a small library for representing semigroup (or monoid)
> actions on a set <http://hackage.haskell.org/package/semigroups-actions>.
> The MultiParamTypeClasses extension seems to be best suited for the task,
> as a group can act on many sets, and a set can be acted on by different
> groups:
> 
>     -- | Represents an action of semigroup  <at> g <at>  to set  <at> a <at> .
>     --
>     -- Laws:  <at> 'Endo' . 'act' <at>  must be a homomorphism of semigroups.
>     class Semigroup g => SemigroupAct g a where
>         act :: g -> (a -> a)
> 
> But soon I realized that with MPTC the compiler has problems inferring
> types and I had to explicitly specify types when using `act` in many
> places. Because it seems that in most cases a set will have only a single
> group acting on it, I was thinking about using FDs:
> 
>     class Semigroup g => SemigroupAct g a | a -> g where
> 
> But on the other hand, this can limit the generality of the type class. I
> cannot decide which one I should choose.
> 
> What would you suggest? According to your experience, would you choose
> plain MPTC or FD?

Another option to consider is not to make this a type class at all.

Something like

  newtype SemigroupAction g a = SemigroupAction { act :: g -> a -> a }

Instead of specifying types you'll be passing SemigroupAction values
(which is arguably less tedious). Plus you don't have to do newtype
wrapping of types and can have as many actions as you want even for the
same pairs of types.

Roman

Gmane