This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?- fibs(F), take(F, 20, _). | |
F = [0, 1, 1, 2, 3, 5, 8, 13, 21|...], | |
freeze(_G2395, zip_with(plus, [2584, 4181|_G2395], [4181|_G2395], _G2395)). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS_GHC -O2 -fno-cse #-} | |
module Main where | |
primesTME = 2 : gaps 3 (joinT [[p*p, p*p+2*p..] | p <- primes']) | |
where | |
primes' = 3 : gaps 5 (joinT [[p*p, p*p+2*p..] | p <- primes']) | |
joinT ((x:xs):t) = x : union xs (joinT (pairs t)) | |
pairs ((x:xs):ys:t) = (x : union xs ys) : pairs t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quicksort3 xs = go xs [] where | |
go (x:xs) zs = part x xs zs [] [] [] | |
go [] zs = zs | |
part x [] zs a b c = go a ((x : b) ++ go c zs) | |
part x (y:ys) zs a b c = | |
case compare y x of | |
LT -> part x ys zs (y:a) b c | |
EQ -> part x ys zs a (y:b) c | |
GT -> part x ys zs a b (y:c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/q/14713387/849891 | |
Write a recursive function squares that takes a list of integers, | |
and returns a list of the squares of those integers in haskell [closed] | |
up vote | |
-7 | |
down vote | |
favorite | |
1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ps = (2:).minus [3..].foldr (\p r-> p*p:union [p*p+p, p*p+2*p..] r) [] $ ps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
So you've got the two bugs: your | |
> isprimerec _ 1 = False | |
> isprimerec n t = if (n `rem` t) == 0 then False else isprimerec n (n-1) | |
should have been | |
> isprimerec _ 1 = True | |
> isprimerec n t = if (n `rem` t) == 0 then False else isprimerec n (t-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Generating primes in Haskell | |
"I have been learning Haskell over the last few days, through Learn You A Haskell. | |
I've been attempting to complete some Project Euler problems, some of which require | |
primes. However the function I have written to try to generate some (in this case | |
primes below 20000) isn't outputting correctly. When I run it, GHCi returns '[1, ' and | |
seemingly doesn't terminate. The code I am using is: | |
> sieve :: (Integral a) => a -> [a] -> [a] | |
> sieve 20000 list = list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fmap :: (a->b) -> foo a -> foo b (a->b) -> (p->a) -> (p->b) | |
fmap :: (c->d) -> bar c -> bar d (c->d) -> (q->c) -> (q->d) | |
(.) :: (t->u) -> (s->t) -> (s->u) | |
(.) fmap :: -- t ~ (a->b) ; u ~ (foo a->foo b) | |
(s->a->b) -> (s->foo a->foo b) (s->a->b) -> (s->(p->a)->(p->b)) | |
(.) fmap fmap :: s ~ (c->d) ; a ~ (bar c) b ~ (bar d) | |
( (c->d) -> foo(bar c) -> foo(bar d) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
B is simply defined as | |
B f g x = f (g x) | |
When we supply it with two args, | |
it still needs the third. (B f g) needs one more argument. | |
Let's see what is B B B. It supplies two args to the first B, | |
so we need to add the third there: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g x y = (return . (+x)) =<< y | |
= (=<<) (return . (+x)) y | |
= ((=<<) . (return .)) ((+) x) y | |
= (=<<) . (return .) . (+) $ x y | |
h mx my = mx >>= (\x -> | |
my >>= (\y -> | |
return (x+y) )) | |
h mx my = do x <- mx |
OlderNewer