Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Haskell is a purely functional programming language, featuring static typing, lazy evaluation, and monadic effects. The primary implementation is GHC, a high-performance compiler with a runtime supporting many forms of parallelism and concurrency.
15
votes
1
answer
1k
views
Finding Local Maxima
The following function finds all local maxima.
A local maxima is an element of a list such that it's greater than either of its neighbor elements. An element with 1 neighbor is not a local maximum.
…
10
votes
1
answer
365
views
Simulate Random Risk Battle
Yorgey's 2013 Haskell course, I'm working on a homework to simulate a Risk battle. …
10
votes
1
answer
893
views
Random Coin Toss in Haskell
Learn You a Haskell gives an exercise to implement the following function:
-- make a function that simulates tossing a function 3 times
import System.Random
tossCoin3 :: Int -> (Bool, Bool, Bool)
tossCoin3 …
10
votes
2
answers
6k
views
Implementing nub (distinct)
I've implemented the following nub' or "give distinct elements of list" function:
nub' :: (Eq a) => [a] -> [a]
nub' [] = []
nub' xs = nubHelper xs []
nubHelper :: (Eq a) => [a] -> [a] -> [a]
nubHelp …
8
votes
3
answers
7k
views
Implementing Transpose
I'm implementing transpose in Haskell.
-- transpose [[1,2,3],[4,5,6],[7,8,9]]
-- [[1,4,7],[2,5,8],[3,6,9]]
Please give it a look. … []
head' (x:xs) = [x]
tail' :: [a] -> [a]
tail' [] = []
tail' (x:xs) = xs
flatten' :: [[a]] -> [a]
flatten' as = foldl (\acc x -> acc ++ x) [] as
Side note - I know that I could look at the Haskell …
8
votes
1
answer
5k
views
Update Map in Haskell
I wrote a function that inserts or updates a Map key value depending on whether the key is already in the map. If it is, then the value gets added to the already existing map's value.
import Data.Map …
7
votes
4
answers
2k
views
Implementing Haskell's `unwords`
Learn You a Haskell explains the unwords function.
$unwords ["hey","there","mate"]
"hey there mate"
Here's my implementation. …
7
votes
1
answer
1k
views
Implementing `split`
I implemented the split function in Haskell:
split :: (Eq a) => a -> [a] -> [[a]]
split _ [] = []
split x ys = f : split x rest
where (f, rest) = break (== x) (dropWhile (== x) ys)
Note that I'm …
7
votes
1
answer
277
views
Fermat Factorization
Please review my implementation of Fermat's Factorization.
fermat :: Int -> Maybe (Int, Int)
fermat n = odd' n >> (go $ ceiling $ sqrt (fromIntegral n))
where go a = case (try n a) of j @ (Just _ …
7
votes
1
answer
558
views
Implement Fibonacci with `iterate`
I implemented the Fibonacci sequence using iterate.
import Data.List
fib :: Int -> Maybe Int
fib n
| n < 0 = Nothing
| otherwise = (fmap (snd . fst)) $ find (\(_,i) -> n == i) (zip res [0..]) …
6
votes
1
answer
3k
views
Is a List Sorted?
This function checks if a list is sorted.
isSorted' :: (Ord a) => [a] -> [a] -> a -> Bool
isSorted' [] [] _ = True
isSorted' (x:xs) [] _ = isSorted' xs xs (head xs)
isSorted' orig (x:xs) a
| a > x …
6
votes
1
answer
3k
views
Reverse Polish Notation Calculator
Working through Learn You a Haskell, I made a Reverse Polish Notation calculator. …
6
votes
1
answer
59
views
Searching a Join List for an index Attempt #2
Originally I posted this incorrect attempt - Searching a Join List for an index.
Given a JoinList:
data JoinList m a = Empty
| Single m a
| Append m (JoinList m a …
5
votes
2
answers
2k
views
Writing Data.List's intersperse
Learn You a Haskell shows the intersperse function:
ghci> intersperse '.' …
5
votes
1
answer
4k
views
Haskell's `group` Function
I implemented the group function:
group' :: (Ord a) => [a] -> [[a]]
group' [] = []
group' xs = takeWhile (== head' xs) (sorted xs) :
(group' $ dropWhile (== head' xs) (sor …