Fwd: [Haskell-beginners] Monad instances and type synonyms

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

It does not really make sense to make a type synonym an instance of some
class, because a type synonym is just just what is says -- another name for
some type. So making a type synonym for some type T an instance of a class
would be the same as making T itself an instance of the class.
Typically you would make Adjustment its own type using newtype:
newtype Adjustment a = Adjustment (SaleVariables -> a)
Ofcourse now it needs its own constructor (like you said you don't want it
to).
/Johan
2013/4/14 Christopher Howard
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
Reply-To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell To: Haskell Beginners 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.
-- frigidcode.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Maybe you can try "curried" definition:
type Adjustment = (->) SaleVariables
I had a similar problem awhile ago.
Hth
—
On Sun, Apr 14, 2013 at 9:11 AM, Christopher Howard

Oh, I see that I'm late to the party, sorry, wasn't able to push my mail for some time
—
On Sun, Apr 14, 2013 at 3:09 PM, Daniil Frumin
Maybe you can try "curried" definition: type Adjustment = (->) SaleVariables I had a similar problem awhile ago. Hth — On Sun, Apr 14, 2013 at 9:11 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 Reply-To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell To: Haskell Beginners 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. -- frigidcode.com <Attached Message Part>

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
Reply-To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell To: Haskell Beginners 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
participants (4)
-
Christopher Howard
-
Daniil Frumin
-
Johan Holmquist
-
Steffen Schuldenzucker