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.
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. …
5
votes
1
answer
1k
views
Computation for finding the largest prime factor of 600851475143 is slow
Please review my implementation for correctness and idiomatic Haskell. …
2
votes
2
answers
74
views
Implementing Traversable for Coproduct
Given the following definitions of Functor and Coproduct from fp-course:
class Functor f where
(<$>) ::
(a -> b)
-> f a
-> f b
class Functor f => Applicative f where
pure ::
a - …
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.
…
1
vote
2
answers
3k
views
Haskell's `partition`
Learn You a Haskell mentions the partition function:
partition takes a list and a predicate and returns a pair of lists. …
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 …
4
votes
1
answer
284
views
Using QuickCheck to Verify Free Monad's Functor Instance
Given the Free Monad, and my Eq, Show, and Functor instances, I attempted to verify the first Functor law using QuickCheck:
data Free f a = Var a
| Node (f (Free f a))
I defined the …
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 …
3
votes
1
answer
60
views
Implementing `dropJ` to Drop `JoinList` Elements
In the same vein as the (+++) function on JoinList and indexJ on JoinList, I implemented dropJ to drop elements from a JoinList.
Here's my attempt:
dropJ ::(Sized b, Monoid b) => Int -> JoinList b a …
2
votes
1
answer
66
views
Conduit Exercise
conduit offers the following exercise:
Write a conduit that consumes a stream of Ints. It takes the first Int from the stream, and then multiplies all subsequent Ints by that number and sends them …
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 …
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 …
4
votes
1
answer
273
views
Implementing Functor Instance for `ITree`
Looking at this Typeclassopedia exercise, I typed out foldTree on the following type:
data ITree a = Leaf (Int -> a) | Node [ITree a]
And my implementation of Functor:
instance Functor (ITree) whe …
3
votes
2
answers
90
views
Implementing Division of Streams (where it's a stream of polynomial coefficients)
Per this homework, I'm trying to implement a Fractional (Stream Integer) where the stream represents coefficients of polynomials:
where Q is defined as Q = (A'/b0) + x((1/b0)(A' − QB0)).
wher …
3
votes
2
answers
593
views
Implementing `concat` using `foldTree` on Rose Tree
I attempted (incorrectly) to implement foldTree here.
Recently, I updated it per Petr's help:
treeFold :: (b -> [b] -> b) -> (a -> b) -> Tree a -> b
treeFold f g tree = f (g (rootLabel tree)) (map ( …