Questions tagged [haskell]
Haskell is a purely functional programming language featuring strong static typing, lazy evaluation, extensive parallelism and concurrency support, and unique abstraction capabilities.
haskell
51,420
questions
1
vote
0
answers
51
views
Constructor classes: why not mention the content's type?
Following on from this q about monad transformers ...
Before constructor classes were introduced [M.P.Jones 1993], Haskell class decls:
Must have a single parameter;
That parameter must be kind Type (...
0
votes
1
answer
42
views
If we bind two parsers and the second parser fails, does the string get parsed once?
So suppose this is a parser:
data Parser a = MkParser (String -> Maybe (String, a))
runParser :: Parser a -> String -> Maybe a
runParser (MkParser sf) inp = case sf inp of
...
1
vote
1
answer
40
views
How to parse CFG with operators
Ok so I have this parser and data:
module SO where
import Data.Char
import Prelude hiding (fmap, (>>=), (*>), (<*), pure)
data Parser a = MkParser (String -> Maybe (String, a))
data ...
2
votes
3
answers
80
views
Haskell list sum generalization
I was working in Python and created an example of how we can generalize the usual sumList function to sum any arbitrary list of lists:
To sum any list of numbers in Python we can write:
def sumList(...
3
votes
1
answer
49
views
How to properly step through recursive parsing?
The code I have is this:
-- my parser, takes a function that takes a string and gives
-- the suffix and the answer
data Parser a = MkParser (String -> Maybe (String, a))
unParser :: Parser a ->...
0
votes
1
answer
52
views
Cabal upload package fails with Encountered missing or private dependency
I'm trying to upload my first Haskell package:
$ git clone https://github.com/OrenGitHub/dhscanner.ast.git 2>/dev/null
$ cd dhscanner.ast/
$ cabal --version
cabal-install version 3.10.1.0 # <--- ...
1
vote
1
answer
48
views
How do I extract this text from an xml file in Haskell
I have an xml file in a similar format to this. There are multiple parent tags:
<file>
<parent title = "counting">
<child>
<notme></notme>
<me>One <...
7
votes
1
answer
85
views
Extending types in a backward compatible way?
Let's say I have:
data X = X Int Char Whatever
Now let's say I want to add a type parameter to X like so:
data Version = OldVersion | NewVersion
data X (phantomParam :: Version) = X Int Char ...
3
votes
1
answer
66
views
Where is the inner m quantified over?
@pash writes:
there's really no such thing as an "unquantified" type signature in Haskell.
Here's a program:
{-# LANGUAGE Haskell98, ScopedTypeVariables, InstanceSigs #-}
module Identity ...
0
votes
0
answers
36
views
How to protect against XSS attacks in Servant Framework?
I have an S2S API which takes in user input and some of that input later gets sent to the frontend. If the user data contains any html like <script> tags, I want to throw a Bad Request 400 ...
0
votes
1
answer
26
views
How to use custom HTML attributes with Blaze in Haskell
I'm trying to write the following HTML element from Bootstrap in blaze-html in Haskell.
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-...
4
votes
2
answers
56
views
What does it mean in Haskell when a function doesn't handle every constructor of a data type?
Consider
data Pair = Pair (Headers, Builder)
| CompoundPair (Headers, [Pair])
showBoundPart :: Boundary -> Pair -> Builder
showBoundPart (Boundary b) (Pair (headers, content)) = ...
3
votes
1
answer
52
views
Why does GHC's type-checker accept this UndecidableInstance trick?
GHC accepts the following code.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
class Blib b where
blib :: b
class Blob b where
blob :: b
instance Blib b => Blob b ...
0
votes
0
answers
69
views
How to run an inner "ServerT" with different context to the outer "ServerT"
We are writing custom servant combinators to handle various authorisation layers in our application. E.g. if you had a task management system, you might have an outermost scope where no authentication ...
2
votes
1
answer
63
views
What's the difference between placing a parser in its "box" vs using it without it? [duplicate]
So this is my parser, and two functions to run a parser:
data Parser a = MkParser (String -> Maybe (String, a))
unParser :: Parser a -> String -> Maybe (String, a)
unParser (MkParser a) inp =...