why are implicit types different? (cleanup)

Why do g and g' have different types? g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) g :: [Char] -> [Char] -> [Char] g' :: (Show t) => [Char] -> t -> [Char] g' x y = let f = \x-> x in f x ++ (show (f y)) Is there a way I can use implicit types and let g be as general as g'? -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com

Implicit parameters have monotypes, not polytypes. So ?f in g gets type (Char->Char). I rather doubt that something more general (implicit parameters get polytypes) would work, given the implicit "improvement" rules that implicit parameters require. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of S. | Alexander Jacobson | Sent: 21 November 2006 19:28 | To: haskell-cafe@haskell.org | Subject: [Haskell-cafe] why are implicit types different? (cleanup) | | | | Why do g and g' have different types? | | g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) | g :: [Char] -> [Char] -> [Char] | | g' :: (Show t) => [Char] -> t -> [Char] | g' x y = let f = \x-> x in f x ++ (show (f y)) | | Is there a way I can use implicit types and let g be as general as g'? | | -Alex- | | | ______________________________________________________________ | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe

Ok, I'm not sure I understand the answer here, but how about a workaround. My current code looks like this: tt = let ?withPassNet=wpn ?withPassNet'=wpn ?withPassNet''=wpn in passNet "passnet" ["user"] regImpl b The type of wpn is: wpn :: Ev PassNet ev a -> Ev State ev a The individual implicit parameters end up arriving with concrete values for a. If I pass wpn to passNet explicitly, it also appears to get converted to a monotype on arrival at the inside of passNet. So I guess the real question is, how do I pass a polytype* wpn? -Alex- * I would have thought the word was polymorphic, but you obvoiusly know. ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com On Mon, 27 Nov 2006, Simon Peyton-Jones wrote:
Implicit parameters have monotypes, not polytypes. So ?f in g gets type (Char->Char). I rather doubt that something more general (implicit parameters get polytypes) would work, given the implicit "improvement" rules that implicit parameters require.
Simon
| -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of S. | Alexander Jacobson | Sent: 21 November 2006 19:28 | To: haskell-cafe@haskell.org | Subject: [Haskell-cafe] why are implicit types different? (cleanup) | | | | Why do g and g' have different types? | | g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) | g :: [Char] -> [Char] -> [Char] | | g' :: (Show t) => [Char] -> t -> [Char] | g' x y = let f = \x-> x in f x ++ (show (f y)) | | Is there a way I can use implicit types and let g be as general as g'? | | -Alex- | | | ______________________________________________________________ | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe

S. Alexander Jacobson wrote:
Ok, I'm not sure I understand the answer here, but how about a workaround. My current code looks like this:
tt = let ?withPassNet=wpn ?withPassNet'=wpn ?withPassNet''=wpn in passNet "passnet" ["user"] regImpl b
The type of wpn is:
wpn :: Ev PassNet ev a -> Ev State ev a
The individual implicit parameters end up arriving with concrete values for a. If I pass wpn to passNet explicitly, it also appears to get converted to a monotype on arrival at the inside of passNet.
So I guess the real question is, how do I pass a polytype* wpn?
Wrap it inside a newtype, maybe? Ben

| So I guess the real question is, how do I pass a polytype* wpn? and the answer is: | On Mon, 27 Nov 2006, Simon Peyton-Jones wrote: | | > Implicit parameters have monotypes, not polytypes. So an implicit parameter never has a polymorphic type. You can get around this, as Ben suggested I think, by using a newtype to wrap it up: newtype WPN = WPN (forall a. Ev PassNet ev a -> Ev State ev a) Simon So ?f in g gets | > type (Char->Char). I rather doubt that something more general | > (implicit parameters get polytypes) would work, given the implicit | > "improvement" rules that implicit parameters require. | > | > Simon | > | > | -----Original Message----- | > | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of | S. | > | Alexander Jacobson | > | Sent: 21 November 2006 19:28 | > | To: haskell-cafe@haskell.org | > | Subject: [Haskell-cafe] why are implicit types different? (cleanup) | > | | > | | > | | > | Why do g and g' have different types? | > | | > | g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) | > | g :: [Char] -> [Char] -> [Char] | > | | > | g' :: (Show t) => [Char] -> t -> [Char] | > | g' x y = let f = \x-> x in f x ++ (show (f y)) | > | | > | Is there a way I can use implicit types and let g be as general as g'? | > | | > | -Alex- | > | | > | | > | ______________________________________________________________ | > | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com | > | _______________________________________________ | > | Haskell-Cafe mailing list | > | Haskell-Cafe@haskell.org | > | http://www.haskell.org/mailman/listinfo/haskell-cafe | >

I ended up solving it by using a typeclass. My general experience of implicit types has been that they end up being a lot less useful than they appear. Getting the types right ends up being difficult and it is usually better just to be in a monad or as in this case to use typeclasses. I've begun to think of use of implicit types as a sign a "bad smell" in the code and if I have used one somewhere, I try to eliminate it because doing so usually results in better code overall. -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com On Tue, 28 Nov 2006, Simon Peyton-Jones wrote:
| So I guess the real question is, how do I pass a polytype* wpn?
and the answer is:
| On Mon, 27 Nov 2006, Simon Peyton-Jones wrote: | | > Implicit parameters have monotypes, not polytypes.
So an implicit parameter never has a polymorphic type. You can get around this, as Ben suggested I think, by using a newtype to wrap it up:
newtype WPN = WPN (forall a. Ev PassNet ev a -> Ev State ev a)
Simon
So ?f in g gets | > type (Char->Char). I rather doubt that something more general | > (implicit parameters get polytypes) would work, given the implicit | > "improvement" rules that implicit parameters require. | > | > Simon | > | > | -----Original Message----- | > | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of | S. | > | Alexander Jacobson | > | Sent: 21 November 2006 19:28 | > | To: haskell-cafe@haskell.org | > | Subject: [Haskell-cafe] why are implicit types different? (cleanup) | > | | > | | > | | > | Why do g and g' have different types? | > | | > | g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) | > | g :: [Char] -> [Char] -> [Char] | > | | > | g' :: (Show t) => [Char] -> t -> [Char] | > | g' x y = let f = \x-> x in f x ++ (show (f y)) | > | | > | Is there a way I can use implicit types and let g be as general as g'? | > | | > | -Alex- | > | | > | | > | ______________________________________________________________ | > | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com | > | _______________________________________________ | > | Haskell-Cafe mailing list | > | Haskell-Cafe@haskell.org | > | http://www.haskell.org/mailman/listinfo/haskell-cafe | >

On Tue, Nov 28, 2006 at 11:59:01AM -0500, S. Alexander Jacobson wrote:
I ended up solving it by using a typeclass. My general experience of implicit types has been that they end up being a lot less useful than they appear. Getting the types right ends up being difficult and it is usually better just to be in a monad or as in this case to use typeclasses. I've begun to think of use of implicit types as a sign a "bad smell" in the code and if I have used one somewhere, I try to eliminate it because doing so usually results in better code overall.
yes. they are just a bad idea for many reasons IMHO. I think they should be purposefully and forcefully retired so they don't trip up new users to haskell who think they are the right way to do things. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (4)
-
Benjamin Franksen
-
John Meacham
-
S. Alexander Jacobson
-
Simon Peyton-Jones