[Haskell-cafe] wildcards for type variables?

Evan Laforge qdunkan at gmail.com
Thu Jan 14 13:08:56 EST 2010


On Thu, Jan 14, 2010 at 5:19 AM, Ozgur Akgun <ozgurakgun at gmail.com> wrote:
> 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 = <doesn't depend on y>
data ControlY -- phantom type
type Control = Signal ControlY
-- other phantom types follow

takes_specific_signal :: Control -> ...
takes_generic_signal :: 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 }


More information about the Haskell-Cafe mailing list