The point in not allowing partially applied type synonym instances is that it'd make deciding whether a type is an instance of a class much harder.
Cf. here[1] for a similar question with the Category class.

-- Steffen

[1] Attached message. Couldn't find it on the archives..

On 04/14/2013 07:10 AM, Christopher Howard wrote:

I asked this question in Haskell-beginners, but I haven't heard anything
yet, so I'm forwarding to Cafe.

-------- Original Message --------
Subject: [Haskell-beginners] Monad instances and type synonyms
Date: Sat, 13 Apr 2013 17:03:57 -0800
From: Christopher Howard<christopher.how...@frigidcode.com>
Reply-To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell<beginn...@haskell.org>
To: Haskell Beginners<beginn...@haskell.org>

I am playing around with some trivial code (for learning purposes) I
wanted to take

code:
--------
-- SaleVariables a concrete type defined early

-- `Adjustment' represents adjustment in a price calculation
-- Allows functions of type (a ->  Adjustment a) to be composed
-- with an appropriate composition function
type Adjustment a = SaleVariables ->  a
--------

And put it into

code:
--------
instance Monad Adjustment where

   (>>=) = ...
   return = ...
--------

If I try this, I get

code:
--------
Type synonym `Adjustment' should have 1 argument, but has been given none
In the instance declaration for `Monad Adjustment'
--------

But if I give an argument, then it doesn't compile either (it becomes a
"*" kind). And I didn't want to make the type with a regular "data"
declaration either, because then I have to give it a constructor, which
doesn't fit with what I want the type to do.




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

--- Begin Message ---

Hi Markus,

On 07/06/2011 03:04 PM, Markus Läll wrote:
[...]

import Control.Arrow
import Control.Category

type X a b = [a] ->  [b]

instance Category X where
    id = map Prelude.id
    g . f = g Prelude.. f

instance Arrow X where
    arr f = map f
    first f = unzip>>>  first f>>>  uncurry zip

The problem is that it's not allowed to use partially applied type
synonyms. It is however possible to define a type synonym which value
is a partially applied type, but I haven't been able to figure out if
I could somehow use that fact in defining the X... Is it at all
possible, or is a newtype the only way to do it?


You should really use a newtype for that. Allowing partially applied type synonyms would greatly increase the expressiveness of the type language. (too much, actually)
In fact, you could write arbitrary type level lambdas, like that:

> type Y b a = [a] -> [b]

But now, given instances like this:

> instance Category X where ...
>
> instance Category Y where ...
> -- uh, yeah, does it make sense in this case? Whatever, we *could* have an instance.

, any function of type [a] -> [b] will match both instances. So which instance to choose? We have two solutions:

a) The compiler discovers itself that we have overlaps here and complains.

This seems hard to me (is it even possible in finite time?). Note that it is easy if type synonyms are always fully applied because the compiler just has to fill in the definition of all the types and can then proceed to compare just the instance *heads*.

b) You somehow annotate which instance to choose for each specific case. But that's exactly what newtypes are for!

The problem does indeed occur in your example: What is (id :: [a] -> [b]) supposed to be, Prelude.id (as given by the general instance for functions) or map Prelude.id (given by your instance)?

-- Steffen

--- End Message ---
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to