Friday, November 09, 2007

Haskell in the Shower

I thought this up while in the shower this morning. I think of the weirdest things in the morning when I'm half-asleep.


___ ___ _
/ _ \ /\ /\/ __(_)
/ /_\// /_/ / / | | GHC Interactive, version 6.4.1, for Haskell 98.
/ /_\\/ __ / /___| | http://www.haskell.org/ghc/
\____/\/ /_/\____/|_| Type :? for help.

Loading package base-1.0 ... linking ... done.
Prelude> :m +List
Prelude List> let primes ns = nubBy d ns where d x y = y `mod` x == 0
Prelude List> primes [2..100]
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]



(Of course, this is not an especially good way of finding primes. It is more like a funny use of nubBy.)

No comments: