[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] Why can't we make an instance declaration on a type

Subject: Re: [Haskell-cafe] Why can't we make an instance declaration on a type synonym?
From: Brandon Simmons
Date: Mon, 4 Jan 2010 11:50:57 -0500
On Sun, Jan 3, 2010 at 2:22 AM, Ivan Lazar Miljenovic
<[email protected]> wrote:
> jberryman <[email protected]> writes:
>
>> This may be a dumb question, but why can we not declare a Monad
>> instance of a type synonym? This question came to me while working
>> with the State monad recently and feeling that the requirement that we
>> wrap our functions in the State constructor is a bit... kludgy.
>>
>
> Because type defines an _alias_.  If you define "type Foo = Maybe Int",
> then everywhere you have a "Foo" the compiler should be able to replace
> it with "Maybe Int".
>
> As such, if you have a custom instance on your type synonym (say a
> custom Show instance for Foo), then which instance will the compiler
> use?


Thanks. I guess what I'm really asking is if there is any way to
redefine the monad instance for (->) such that we can have a State
monad without the data constructor wrapper.

It sounds like there probably isn't, but it seems like that would be a
pretty useful thing to be able to do generally.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>