Skip to content

Instantly share code, notes, and snippets.

View ta0kira's full-sized avatar

Kevin P. Barry ta0kira

View GitHub Profile
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@ta0kira
ta0kira / primes.hs
Last active September 24, 2021 18:27
An infinite list of primes, written in Haskell.
import Control.Applicative ((<|>))
import Data.Maybe (fromJust)
-- The primary task: Compute primes
-- Infinite list of primes
primes = iterate nextPrime 2 where
nextPrime y = head [x | x <- [succ y..], hasNoFactors x]
hasNoFactors x = fromJust $ foldr (<|>) Nothing $ map check primes where