wildcards for type variables?

Occasionally I have a function with an unused argument, whose type I don't want to restrict. Thus: f :: _unused -> A -> B f _ a = b Since it's a little unusual, I try to make it clear that the type is intentionally ignored. But it makes me wonder, would it make sense to allow _ as a type variable name, with the same meaning as in pattern matching?

On Jan 13, 2010, at 05:54 , David Virebayre wrote:
On Wed, Jan 13, 2010 at 12:29 AM, Evan Laforge
wrote: Occasionally I have a function with an unused argument, whose type I don't want to restrict. Thus:
f :: _unused -> A -> B f _ a = b
I probably misunderstood the problem, why not f:: a -> A -> B
He's looking for the self-documentation aspect of "this argument is completely irrelevant". Neither rolling a random unused type variable nor "forall"ing it (my first idea) really accomplishes that. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On Wed, Jan 13, 2010 at 4:59 AM, Brandon S. Allbery KF8NH
On Jan 13, 2010, at 05:54 , David Virebayre wrote:
On Wed, Jan 13, 2010 at 12:29 AM, Evan Laforge
wrote: Occasionally I have a function with an unused argument, whose type I don't want to restrict. Thus:
f :: _unused -> A -> B f _ a = b
I probably misunderstood the problem, why not f:: a -> A -> B
He's looking for the self-documentation aspect of "this argument is completely irrelevant". Neither rolling a random unused type variable nor "forall"ing it (my first idea) really accomplishes that.
Isn't that what we have here? a function of type (a -> A -> B) cannot use the first argument in any meaningful way. But once you start throwing in higher ranked types you might have to think a bit to come to that conclusion. Antoine

On Jan 13, 2010, at 2:16 PM, Antoine Latter wrote:
He's looking for the self-documentation aspect of "this argument is completely irrelevant". Neither rolling a random unused type variable nor "forall"ing it (my first idea) really accomplishes that.
Isn't that what we have here? a function of type (a -> A -> B) cannot use the first argument in any meaningful way.
I think, he wants to document that the type variable 'a' is not used in the *type*. Just like you can document that the second argument of 'const' is unused by using a wildcard. You can write const x _ = x instead of const x y = x and it would be nice to write 'const's type as a -> _ -> a rather than a -> b -> a Sebastian -- Underestimating the novelty of the future is a time-honored tradition. (D.G.)

Isn't that what we have here? a function of type (a -> A -> B) cannot use the first argument in any meaningful way.
I think, he wants to document that the type variable 'a' is not used in the *type*.
Yeah, that's the idea, sorry if I wasn't clear. In the case of const, I might write const :: a -> _b -> a To document that 'b' intentionally appears only once, but this is only my convention and I've never seen anyone else use it. In the case of 'const' it's pretty obvious and unnecessary, but in a longer signature it might help a bit, especially if you are using phantom types and some functions intentionally ignore type arguments. I haven't used them before, but in the presence of scoped type variables, wouldn't have a reader have to go look for internal definitions to reassure himself that the type is in fact ignored entirely? It's not a big issue, but it seemed like a nice symmetry with pattern matching syntax.

On Jan 13, 2010, at 6:54 PM, Evan Laforge wrote:
It's not a big issue, but it seemed like a nice symmetry with pattern matching syntax.
And I don't think it's a weird idea. The "Haskell dialect" Curry [1] supports this syntax. Maybe the hurdle for Haskell is the competition with more complex, conflicting proposals like [2]. Sebastian [1] http://curry-language.org [2] http://hackage.haskell.org/trac/haskell-prime/wiki/PartialTypeSigs -- Underestimating the novelty of the future is a time-honored tradition. (D.G.)

Can someone give an example of a "reasonable" function that never uses one
of its parameters, and justify the existence of that parameter in this case,
please?
Because for this example,
f :: _unused -> A -> B
f _ a = b
I think what I'd do is to write the function f without that first parameter,
and call the funcrtion accordingly.
Best,
2010/1/13 Sebastian Fischer
On Jan 13, 2010, at 6:54 PM, Evan Laforge wrote:
It's not a big issue, but it seemed like a nice symmetry with pattern
matching syntax.
And I don't think it's a weird idea. The "Haskell dialect" Curry [1] supports this syntax. Maybe the hurdle for Haskell is the competition with more complex, conflicting proposals like [2].
Sebastian
[1] http://curry-language.org [2] http://hackage.haskell.org/trac/haskell-prime/wiki/PartialTypeSigs
-- Underestimating the novelty of the future is a time-honored tradition. (D.G.)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ozgur Akgun

Ozgur Akgun
Can someone give an example of a "reasonable" function that never uses one of its parameters, and justify the existence of that parameter in this case, please?
I would like to bring your attention to the "const" function: ,---- | const :: a -> b -> a | const a _ = a `---- For justification, I often use this function when I need to provide a function that takes two arguments by the function I want to use only needs one; as such either const of (flip const) can let me absorb and ignore the unneeded argument. Satisfied? ;-) -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Ozgur Akgun
Can someone give an example of a "reasonable" function that never uses one of its parameters, and justify the existence of that parameter in this case, please?
E.g, 'const' is useful when you need something to feed to a higher order function: -- an element <=3 starts a new group *Main> groupBy (const (>3)) [1,2,3,4,1,5,6] [[1],[2],[3,4],[1,5,6]] Not the best example, perhaps, but the existence of const allows you to easily reuse existing framework. There's also 'par', although it's raison d'être is to have an effect on the second parameter, so it is arguably "using" it. -k -- If I haven't seen further, it is by standing in the footprints of giants

On Thu, Jan 14, 2010 at 5:19 AM, Ozgur Akgun
Can someone give an example of a "reasonable" function that never uses one of its parameters, and justify the existence of that parameter in this case, please?
As I mentioned, this is not only about parameters, but about type
variables. From my own code:
data Signal y =
Because for this example, f :: _unused -> A -> B f _ a = b I think what I'd do is to write the function f without that first parameter, and call the funcrtion accordingly.
It's common (for me at least) to write 'modify' functions that look like "modify_x :: (X -> X) -> SomeMonad ()". You don't need to write the 'set' variant if you have const. That said, 'const' is already in the Prelude. But ignored args also turn up when you need a common signature, this also occurs a number of times in my own code: this_way :: X -> Y -> Z that_way :: X -> _y -> Z -- doesn't need Ys testing_way :: _x -> _y -> Z ... modify_rec $ const $ rec { rec_doit = if do_this_way then this_way else that_way }
participants (8)
-
Antoine Latter
-
Brandon S. Allbery KF8NH
-
David Virebayre
-
Evan Laforge
-
Ivan Lazar Miljenovic
-
Ketil Malde
-
Ozgur Akgun
-
Sebastian Fischer