RE: Haskell-Cafe Digest, Vol 28, Issue 66

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

RE: Haskell-Cafe Digest, Vol 28, Issue 66

Chad Scherrer-2
> From: Daniel Carrera <[hidden email]>
> Robert Dockins wrote:
> > -divides a b = (mod a b == 0)
> > +divides a b = (mod b a == 0)
>
> Oh, thanks. My program assumed one way to define 'divides'
> and the example assumed the other.
>
> When I wrote it I was thinking of (divides a) being a
> function that tells me if the input divides 'a'.
>
> Thanks!
>
> Cheers,
> Daniel.

Daniel,

Have you used Haskell's infix notation? It can help keep the order
straight for operators like these. You can write

a `mod` b  -- instead of mod a b
a `divides` b -- instead of divides a b.

This can help with readability, too.

Chad Scherrer
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell-Cafe Digest, Vol 28, Issue 66

Daniel Carrera-2
Scherrer, Chad wrote:
> Have you used Haskell's infix notation? It can help keep the order
> straight for operators like these. You can write
>
> a `mod` b  -- instead of mod a b
> a `divides` b -- instead of divides a b.
>
> This can help with readability, too.

No, I haven't. That's neat, very neat. Thanks for the tip.

I just tried it, and all these are valid:

(a `divides`) b
(`divides` b) a

That's neat because then you can make derived functions and compositions
and all sorts of neat stuff.

Cheers,
Daniel
--
      /\/`) http://oooauthors.org
     /\/_/  http://opendocumentfellowship.org
    /\/_/
    \/_/    I am not over-weight, I am under-tall.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Re: infix functions

David Roundy
On Tue, Dec 20, 2005 at 09:12:51PM +0000, Daniel Carrera wrote:
> No, I haven't. That's neat, very neat. Thanks for the tip.
>
> I just tried it, and all these are valid:
>
> (a `divides`) b
> (`divides` b) a

The annoyance in this business (which *is* very cool) is that you really
have to decide when you name your functions whether they're meant to be
infix or not.  At least I've never come up with a verb form that makes
sense either infix or prefix... :(
--
David Roundy
http://www.darcs.net
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe