Crea sito

Prime numbers in Haskell

Well, do you want to know how to find 'prime numbers' in a quick and dirty
way using Haskell ?
try this!

import Data.List
nubBy ( \x y -> mod y x == 0 ) [2..]

Haskell is so easy and charming...

( ps: if you want to speed up a little bit:
nubBy ( \x y -> ( x*x-1 <= y ) && ( mod y x == 0 ) ) [2..]
)

ps:
even better:
nubBy(((.).(.))(0==) (flip $ mod)) [2..]

jQuery Menu Tree Based On XML

jXMLTree is a free jQuery plugin to generate tree UI based on predefined XML.
Follow this link: jQuery Menu Tree Based On XML

Haskell or Scala?

Haskell
100% (1 voto)
Scala
0% (0 voti)
Voti totali: 1

Dollar Operator in Haskell

Do you know what is $ operator in Haskell?
$ means simply , 'apply the left function at the right value'.

f $ x := f x

it seems really trivial, isn't it ?
But, for example in this kind of situation, is really usefull:

zipWith ( $ ) ( cycle [ \x -> div (x + 1) 2 , \x -> div x 2 ] ) [1..]

here you have a infinite list of function:

a = cycle [ \x -> div (x + 1) 2 , \x -> div x 2 ]
( ie: [\x -> div (x + 1) 2 , \x -> div x 2 , \x -> div (x + 1) 2 , \x -> div x 2, ... ] )

and you want to apply every element of the list at the element

Primo intervento

link al blog snakelemma blog

Storia

Questo sito nasce oggi 2 agosto 2010

Condividi contenuti