How would you describe a monad in non-programming terms? Is there some concept/thing outside of programming (outside of all programming, not just FP) which could be said to act or be monad-like in a significant way?
...
Hello everyone, I've found such code in the book "Real World Haskell", p68
data Tree a = Node a (Tree a) (Tree a)
| Empty
deriving (Show)
nodeAreSame (Node a _ _) (Node b _ _)
| a == b = Just a
nodeAreSame _ _ = Nothing
My question is: What job did the Just data constructor do? When I delete it, ...
I have the following two functions written.
pair :: [a] -> [(a, a)]
pair [] = []
pair [x] = []
pair (x1:x2:xs) = (x1, x2) : pair xs
unpair :: [(a, a)] -> [a]
unpair [] = []
unpair ((x1, x2):xs) = x1 : x2 : unpair xs
Pair will take pairs of elements and make 2-tuples of them. If the list has an odd number of elements, discard the last...
If I define the "bind" function like this:
(>>=) :: M a -> (a -> M' b) -> M' b
Will this definition help me if I want the result to be of a new Monad type, or I should use same Monad but with b in the same Monad box as before?
...
I'm a .NET developer by day, but have been playing with Haskell in my spare time for awhile now. I'm curious: any Haskell .net implemenations in the same vein as IronPython?
...
UPDATE: Okay this question becomes potentially very straightforward.
q <- mapM return [1..]
Why does this never return?
Does mapM not lazily deal with infinite lists?
The code below hangs. However, if I replace line A by line B, it doesn't hang anymore. Alternatively, if I preceed line A by a "splitRandom $", it also doesn't hang...
I have two non-overlapping sets of types and want to make other set which is union of these two.
Code sample:
class A a
class B b
class AB ab
instance A a => AB a
instance B b => AB b
GHC 6.12.3 doesn't allow to declare this with error message:
Duplicate instance declarations:
instance (A a) => AB a -- Defined at playgro...
Hi fellow stackies.
I am a long time OO programmer and a functional programming newbie. From my little exposure algebraic data types only look like a special case of inheritance to me where you only have one level hierarchy and the super class cannot be extended outside the module.
So my (potentially dumb) question is: If ADTs are jus...
I got nearly no knowledge of haskell and tried to solve some Project Euler Problems.
While solving Number 5 I wrote this solution (for 1..10)
--Check if n can be divided by 1..max
canDivAll :: Integer -> Integer -> Bool
canDivAll max n = all (\x -> n `mod` x == 0) [1..max]
main = print $ head $ filter (canDivAll 10) [1..]
Now I fo...
In chapter 15 of Real World Haskell, a type class is defined:
class (Monad m) => MonadSupply s m | m -> s where
A couple paragraphs later, it says that >>= and return don't need to be defined because of the context. But there's no further explanation of what it means by context.
How does the compiler know MonadSupply is an instance ...
I'm a bit confused, and need someone to set me straight. Lets outline my current understanding:
Where E is an endofunctor, and A is some category:
E : A -> A.
Since all types and morphisms in Haskell are in the Hask category, is not any functor in Haskell also an endofunctor? F : Hask -> Hask.
I have a good feeling that I'm wrong, a...
Here is the output from verbose mode. I know this used to work for me before but now this happens. I've tried it with other packages and got the same result.
$ sudo cabal install test-framework-quickcheck2 -v
/usr/local/bin/ghc --numeric-version
looking for package tool: ghc-pkg near compiler in /usr/local/bin
found package tool in /u...
I'd like to divide two Int values in Haskell and obtain the result as a Float. I tried doing it like this:
foo :: Int -> Int -> Float
foo a b = fromRational $ a % b
but GHC (version 6.12.1) tells me "Couldn't match expected type 'Integer' against inferred type 'Int'" regarding the a in the expression.
I understand why: the fromRati...
Lets say we have this type declaration:
data D a = A a | B a | C a | D a | E a | F a
and want to define a function over it which divides the data constructors in 2 sets. It would be nice to write something like that:
g x | x `is` [A,B,C] = 1
| x `is` [D,E,F] = 2
instead of matching on each constructor separately.
Is there any ...
While solving some Project Euler Problems to learn Haskell (so currently I'm a completly beginner) I came over Problem 13. I wrote this (naive) solution:
--Get Number of Divisors of n
numDivs :: Integer -> Integer
numDivs n = toInteger $ length [ x | x<-[2.. ((n `quot` 2)+1)], n `rem` x == 0] + 2
--Generate a List of Triangular Values
...
Hi,
I'm trying to rewrite a fairly simple MATLAB script in Haskell. I'm looking for an equivalent to MATLAB's fsolve (numerical root finder) and ode15s (one of the ODE solvers). On Hackage there seems to be a MATLAB interface package. Is this the way to go (in terms of speed, simplicity, etc.) or are there other packages that would be m...
Coming to Haskell from a background in various OO languages, one thing that seems like a bit of a drawback to me is that function and field names aren't scoped to the types they're associated with, so it's easy to run into clashes if different datatypes have fields with the same name.
If I have these three modules:
module One where
da...
I'm having a difficult time figuring out the set of packages I need to get Haskell OpenGL working on Ubuntu 10.04.
Could someone please provide me with the list of APT packages and the list of CABAL packages I need to get to successfully start the OpenGL tutorial here?
...
parserChar :: Char -> Parser Char
parserChar c = Parser ch where
ch d = case dvChar d of
Parsed c dp -> Parsed c dp
_ -> NoParse
The above function is supposed to take a Char c and return a Parser which will only match c. The function dvChar d is going to return either Parsed char dp or NoParse (where char is the next ch...
I found this code on the front page of the Yesod project:
import Yesod
data HelloWorld = HelloWorld
mkYesod "HelloWorld" [$parseRoutes|/ Home GET|]
instance Yesod HelloWorld where approot _ = ""
getHome = applyLayout [$hamlet|%h1 Hello World|]
main = toWaiApp HelloWorld >>= basicHandler 3000
What language features are used in [$parseR...