Verified Commit 4d294fe2 authored by Thimo Neumann's avatar Thimo Neumann
Browse files

Initial commit.

parents
# Own:
*.exe
# From https://raw.githubusercontent.com/github/gitignore/master/Haskell.gitignore
dist
dist-*
cabal-dev
*.o
*.hi
*.hie
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
MIT License
Copyright (c) 2020 Thimo Neumann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
import SieveOfEratosthenes
main = putStrLn (show (take 10 (primes) ) )
.SUFFIXES: .hs .exe
.PHONY: default runhaskell run clean
default: runhaskell
runhaskell: Main.hs SieveOfEratosthenes.hs
runhaskell Main.hs
Main.exe: Main.hs SieveOfEratosthenes.hs
ghc --make Main.hs
run: Main.exe
Main.exe
clean:
cmd /C "DEL /S /F /Q *.o"
cmd /C "DEL /S /F /Q *.hi"
cmd /C "DEL /S /F /Q *.exe"
# find -iname "*.o" -delete
# find -iname "*.hi" -delete
# find -iname "*.exe" -delete
# Calculating The Sieve Of Eratosthenes
This project contains the code used within the paper
[Functional Pearl: Calculating the Sieve of Eratosthenes](https://www.kestrel.edu/home/people/meertens/publications/papers/Calculating_the_Sieve_of_Eratosthenes.pdf)
by Lambert Meertens.
Further code is added for demonstration purposes.
## Running
To run this project simply use `runhaskell Main.hs`.
This can also be done by calling `make` or `make runhaskell`.
An executable file can be produced by calling `make build`.
## Project Structure
The file [`SieveOfEratosthenes.hs`](/SieveOfEratosthenes.hs) contains the core functions for this application.
## License
This project is licensed under the [MIT License](/LICENSE).
module SieveOfEratosthenes
(
primes
) where
primes :: (Integral a) => [a]
primes = sieve [2..]
sieve :: (Integral a) => [a] -> [a]
sieve (p : ns) = p : sieve (filter (notdiv p) ns)
notdiv :: (Integral a) => a -> a -> Bool
notdiv d n = n `mod` d /= 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment