Hi all,
Please bear with me as I am very new to functional programming and Haskell. I am attempting to write a function in Haskell that takes a list of Integers, prints the head of said list, and then returns the tail of the list. The function needs to be of type [Integer] -> [Integer]. To give a bit of context, I am writing an inter...
Hi. I need to create a parser for a programming language. So far it is 95% done, I'd say, except for a tiny detail.
The program written in this language has the following structure:
outputs
inputs
expressions
The requirement is that outputs cannot be mixed with inputs. For example:
x := output of int;
y := output of in;
.....
z := i...
Hi all. My question is simple. Why wrong pattern matching does not throw exception in Maybe monad. For clarity :
data Task = HTTPTask {
getParams :: [B.ByteString],
postParams :: [B.ByteString],
rawPostData :: B.ByteString
} deriving (Show)
tryConstuctHTTPTask :: B.ByteString -> Maybe Task
tryConstuctHTTPTask str = do
case...
dreiNplusEins :: Integer -> [Integer]
dreiNplusEins n = if n == 1 then [1] else if n `mod` 2 == 0 then
[n] ++ dreiNplusEins (n `div` 2)
else
[n] ++ dreiNplusEins (n * 3 + 1)
maxZyklus :: UntereGrenze -> ObereGrenze -> (UntereGrenze,ObereGrenze,MaxZyk...
Suppose we define a GADT for comparison of types:
data EQT a b where
Witness :: EQT a a
Is it then possible to declare a function eqt with the following type signature:
eqt :: (Typeable a, Typeable b) => a -> b -> Maybe (EQT a b)
...such that eqt x y evaluates to Just Witness if typeOf x == typeOf y --- and otherwise to Nothing?
...
How can I convert Int to Integer in Haskell?
...
Given a simple language, say
data E where
ValE :: Typeable a => a -> E
AppE :: E -> E -> E
is it then possible to transform it into a typed representation:
data T a where
ValT :: Typeable a => a -> T a
AppT :: T (a -> b) -> T a -> T b
deriving Typeable
I have tried various approaches, e.g. the following:
e2t :: Typeable ...
t = True
f = False
anzNachbarn :: [[Bool]] -> (Integer,Integer) -> Integer
anzNachbarn a (x,y)
| x < 0 || y < 0=-1
| otherwise ... here comes the comparison
This is an example matrix:
[[True,False,False],
[True,False,False],
[False,True,False]]
here i need an algorithm, where it calculates (for given x and y position...
Hi,
I need to write a state monad that can also support error handling. I was thinking of using the Either monad for this purpose because it can also provide details about what caused the error. I found a definition for a state monad using the Maybe monad however I am unable to modify it to use Either, instead of Maybe. Here's the code:...
I've had the IO monad described to me as a State monad where the state is "the real world". The proponents of this approach to IO argue that this makes IO operations pure, as in referentially transparent. Why is that? From my perspective it appears that code inside the IO monad have plenty of observable side effects. Also, isn't it possi...
The following Haskell program prompts the user for a password in the terminal and continues if he has entered the correct one:
main = do
putStrLn "Password:"
password <- getLine
case hash password `member` database of
False -> putStrLn "Unauthorized use!"
True -> do
...
Unfortunately, the...
Using Parsec 3.1, it is possible to parse several types of inputs:
[Char] with Text.Parsec.String
Data.ByteString with Text.Parsec.ByteString
Data.ByteString.Lazy with Text.Parsec.ByteString.Lazy
I don't see anything for the Data.Text module. I want to parse Unicode content without suffering from the String inefficiencies. So I've c...
My problem is in the last line:
module A where
data A = A { f :: Int }
defaultA = A { f = 0 }
and
module B where
import A as A
data B = B { f :: Int }
bToA :: B -> A
bToA x = defaultA { A.f = f x }
gives
B.hs:8:26:
Ambiguous occurrence `f'
It could refer to either `B.f', defined at B.hs:5:13
...