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.
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 …
2
votes
2
answers
236
views
Implementing Todo in Haskell
Per Learn You a Haskell, I implemented a simple command-line program, Todo, that accepts 1 of 3 arguments: view or add or delete. … Please review my code for Haskell idioms & overall quality.
-- view, add and delete tasks
-- borrows delete from previous LYAH exercise
import System.Environment
import System.Directory
import System.IO …
4
votes
3
answers
395
views
Push List Element to Top
Please evaluate this function. It takes a list [a] and an Int, i.e. the index, and returns a new list with the selected item at the top of the list. Note that it returns Maybe [a] to account for bad i …
0
votes
2
answers
112
views
Chaining Applicatives
I wrote this code to append Maybe's:
ghci> (:) <$> Just 5 <*> ((:) <$> Just 100 <*> Just [])
Just [5,100]
Similarly:
ghci> (:) <$> Just 5 <*> ( (:) <$> Just 10 <*> ((:) <$> Just 100 <*> Just []) ) …
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 …
2
votes
2
answers
819
views
Implement a fold-like Function in Haskell
Is the above code idiomatic in Haskell? …
3
votes
1
answer
124
views
Splitting a List
I wrote the following split function. It takes a list, an element and an Ordering (LT, GT, EQ). For LT, the list will filter out all items that are >= the element argument.
split' :: (Ord a) => [a] - …
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 …
4
votes
1
answer
56
views
Implementing "Pierre the Tight-rope" Walker from LYAH
Learn You a Haskell presents an excellent introduction to >>= with an example. …
1
vote
1
answer
666
views
Find Element in Tree Given a List of Directions
Looking at Learn You a Haskell, I implemented a function that, given a binary tree, i.e. left and right branches, give a list of Directions and give the element at that location. …
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
1
answer
47
views
doSkip Function
I wrote a function, doSkip.
For an N-sized list, an element at index 0 consists of the entire input. Index 1 consists of every other element, i.e. the odd elements. Then, indexes 2 to N consist of th …
1
vote
2
answers
257
views
Monoid Instance for `a -> b` [closed]
I attempted to implement a Monoid' instance for a function a -> b.
class Monoid' a where
mempty :: a -> a
mappend :: a -> a -> a
instance Monoid' (a -> b) where
mempty f = f
mapp …
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 …
1
vote
2
answers
57
views
Implementing (+++) to Join JoinList's
Related to this question, I wrote the (+++) function to join 2 JoinList's:
(+++) :: Monoid m => JoinList m a -> JoinList m a -> JoinList m a
(+++) Empty y = y
(+++) x …