Skip to content

Instantly share code, notes, and snippets.

@0rphee
0rphee / primes.hs
Last active June 21, 2022 18:56
A simple program for calculating the number of prime numbers from 2 to 250000. Using `ghc -02 primes.hs` gave me around 2.9s per run.
isPrime :: Int -> Int
isPrime = helper 2
where helper :: Int -> Int -> Int
helper count num
| prime = if count <= div num 2
then helper (count+1) num
else 1
| otherwise = 0
where prime = (num == 2) || (mod num count /= 0)
@0rphee
0rphee / helix.hs
Created July 8, 2022 00:27
Helix code lens and code actions for Haskell
-- Follow instructions from (https://www.haskell.org/ghcup/) to install Haskell-Language-Server
-- Neither do code actions nor code lenses are available when selecting eligible code, while in other
-- editors they are available
-- More code actions are available in other editors
-- func xs = sum xs
-- func = sum
func :: (Foldable t, Num a)=> t a -> a
func xs = foldl (+) 0 xs