-
Monads in 15 minutes: Backtracking and Maybe
-
Add Sticky Note

-
Backtracking: The lazy way to code
- 7 more annotations...
-
-
The Haskell 98 Library Report: Arrays
-- A rectangular subarray
subArray :: (Ix a) => (a,a) -> Array a b -> Array a b
subArray bnds = ixmap bnds (\i->i)
-- A row of a matrix
row :: (Ix a, Ix b) => a -> Array (a,b) c -> Array b c
row i x = ixmap (l',u') (\j->(i,j)) x where ((_,l'),(_,u')) = bounds x-
16.2 Incremental Array Updates
The operator (//) takes an array and a list of pairs and returns
an array identical to the left argument except that it has
been updated by the associations in the right argument. (As with
the array function, the indices in the association list must
be unique for the updated elements to be defined.) For example,
if m is a 1-origin, n by n matrix, then
m//[((i,i), 0) | i <- [1..n]] is the same matrix, except with
the diagonal zeroed. -
-- A rectangular subarray
subArray :: (Ix a) => (a,a) -> Array a b -> Array a b
subArray bnds = ixmap bnds (\i->i)
-- A row of a matrix
row :: (Ix a, Ix b) => a -> Array (a,b) c -> Array b c
row i x = ixmap (l',u') (\j->(i,j)) x where ((_,l'),(_,u')) = bounds x
-- Diagonal of a matrix (assumed to be square)
diag :: (Ix a) => Array (a,a) b -> Array a b
diag x = ixmap (l,u) (\i->(i,i)) x
where
((l,_),(u,_)) = bounds x
-- Projection of first components of an array of pairs
firstArray :: (Ix a) => Array a (b,c) -> Array a b
firstArray = fmap (\(x,y)->x)
-
-
99 questions/1 to 10 - HaskellWiki
-
data NestedList a = Elem a | List [NestedList a]
flatten :: NestedList a -> [a]
flatten (Elem x) = [x]
flatten (List x) = concatMap flatten x
-
-
Haskell: The Confusing Parts
If you’re used to the C family of languages, or the closely related family of “scripting languages,” Haskell’s syntax (mainly) is a bit baffling at first. For some people, it can even seem like it’s sneaking out from under you every time you think you understand it. This is sort of a FAQ for people who are new to Haskell, or scared away by its syntax.
-
I will point out that
returnis, in fact, not a return
statement. It’s a function, and an inappropriately named function, at that.
Writingreturn ()in yourdoblock will
not cause the function to return. -
The
curryanduncurryfunctions stand in for\f
x y -> f (x, y) - 7 more annotations...
-
