I'm thinking about ways to use Haskell's type system to enforce modularity in a program. For example, if I have a web application, I'm curious if there's a way to separate all database code from CGI code from filesystem code from pure code.
For example, I'm envisioning a DB monad, so I could write functions like:
countOfUsers :: DB In...
I wish to manipulate data on a very low level. Therefore I've a function that receives a virtual memory address as an integer and "does stuff" with this memory address. I interfaced this function from C, so it has the type (CUInt -> a).
The memory i want to link is a Word8 in a File. Sadly i have no idea how to access the pointer value t...
I want to redefine several arithmetic operators in Haskell in order to make them more extensible and generic.
E.g.
class Mul a b c | a b -> c where
(*) :: a -> b -> c
This seems to work in combination with
import Prelude hiding ((*))
hiding the standard * operator. But of course all usual multiplications have to work as well, ...
What I need is to read pdf, make some transformations (generate TOC bookmarks) and write it back.
I found this http://hackage.haskell.org/package/HPDF , but it only mentions generating pdf, not the parsing (although I could have missed it)
Haskell is chosen purely for (self)educational purposes.
...
I am new to Haskell, so I am trying to figure out how to do tree traversals.
Here is the Company example (with a slight change) that I have seen in several papers
data Company = C [Dept] deriving (Eq, Show, Typeable, Data)
data Dept = D Name Manager [Unit] deriving (Eq, Show, Typeable, Data)
data ThinkTank= TK Name ...
Hi
I have followed the tutorial on the Haskell wiki about implementing an IRC bot. and everything worked out fine. But once I started extending it, I realised that It would need to respond to CTCP requests from other users for commands like version and ping. These commands work for the server but not for the bot.
I read the rfc's for C...
So basically, if I have a (finite or infinite) list of (finite or infinite) lists of strings, is it possible to sort the list by length first and then by lexicographic order, excluding duplicates? A sample input/output would be:
Input:
[["a", "b",...], ["a", "aa", "aaa"], ["b", "bb", "bbb",...], ...]
Output:
["a", "b", "aa", "bb", "a...
I don't understand what "lifting" is. Should I first understand Monads before understanding what a "lift" is (I'm completely ignorant about Monads too yet:) ? Or can someone explain it to me with simple words ?
...
To solve some problem I need to compute a variant of the pascal's triangle which is defined like this:
f(1,1) = 1,
f(n,k) = f(n-1,k-1) + f(n-1,k) + 1 for 1 <= k < n,
f(n,0) = 0,
f(n,n) = 2*f(n-1,n-1) + 1.
For n given I want to efficiently get the n-th line (f(n,1) .. f(n,n)). One further restriction: f(n,k) should be -1 if it would...
I am trying to parse F# type syntax. I started writing an [F]Parsec grammar and ran into problems, so I simplified the grammar down to this:
type ::= identifier | type -> type
identifier ::= [A-Za-z0-9.`]+
After running into problems with FParsec, I switched to Parsec, since I have a full chapter of a book dedicated to explaining it. ...
fibs :: [Int]
fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]
This generates the Fibonacci sequence.
I understand the behaviour of the guards, of :, zip and tail, but I don't understand <-. What is it doing here?
...
I'm trying to run this code:
let coins = [50, 25, 10, 5, 2,1]
let candidate = 11
calculate :: [Int]
calculate = [ calculate (x+candidate) | x <- coins, x > candidate]
I've read some tutorials, and it worked out ok.
I'm trying to solve some small problems to give-me a feel of the language. But I'm stuck at this.
test.hs:3:0: parse e...
I'm struggling to understand this type signature:
Prelude Text.Regex.Posix> :t (=~)
(=~)
:: (Text.Regex.Base.RegexLike.RegexMaker
Regex CompOption ExecOption source,
Text.Regex.Base.RegexLike.RegexContext Regex source1 target) =>
source1 -> source -> target
I reckon they list type classes, source, source1 and targ...
Attempting to use Data.Binary.Get and ByteString and not understanding what's happening. My code is below:
getSegmentParams :: Get (Int, L.ByteString)
getSegmentParams = do
seglen <- liftM fromIntegral getWord16be
params <- getByteString (seglen - 2)
return (seglen, params)
I get the following error against the third item...
Can you create a list of functions and then execute them sequentially, perhaps passing them into do notation?
I'm currently doing this by mapping over a list of data and am wondering if I can call somehow pass the result as a series of sequential calls?
...
Is there a valid way to do the following in Haskell:
case n of
0 -> doThis
1 -> doThat
2 -> doAnother
3..99 -> doDefault
other than to have 97 lines of "doDefault" ?
...
(n >= 3 ) && (n <= 99)
OR
n `elem` [3..99]
Which one is faster and why?
...
Hello.
usual wxHaskell program looks like
main = do
run gui
gui = do
....
....
gui must have type IO a, run has type IO a -> IO (), also there is some initialization routines in run.
I'm tring to do following:
data AppGlobals = AG { ... some data ... }
type MApp a = StateT AppGlobals IO a
But in this case g...
Parsec is designed to parse textual information, but it occurs to me that Parsec could also be suitable to do binary file format parsing for complex formats that involve conditional segments, out-of-order segments, etc.
Is there an ability to do this or a similar, alternative package that does this? If not, what is the best way in Hask...
I have been using uniplate and SYB and I am trying to transform a list
For instance
type Tree = [DataA]
data DataA = DataA1 [DataB]
| DataA2 String
| DataA3 String [DataA]
deriving Show
data DataB = DataB1 [DataA]
| DataB2 String
| DataB3 String [DataB]
...