Is there some way (any way) to implement constraints in type classes?
As an example of what I'm talking about, suppose I want to implement a Group as a type class. So a type would be a group if there are three functions:
class Group a where
product :: a -> a -> a
inverse :: a -> a
identity :: a
But those are not any fu...
Can anyone give me a brief example of testing IO actions using Monadic QuickCheck?
...
Is there a no-fuss serialization method for Haskell, similar to Erlang's term_to_binary/binary_to_term calls? Data.Binary seems unnecessarily complicated and raw. See this example where you are basically manually encoding terms to integers.
...
Hey Haskellers,
Right now I'm studying the mtl library, trying to do some MonadTransformers of my own. I was checking the Control.Monad.State.StateT declaration, and across all the code, I see this syntax:
execStateT :: (Monad m) => StateT s m a -> s -> m s
execStateT m s = do
~(_, s') <- runStateT m s
return s'
I'm wondering, wh...
I'm currently making a scanner for a basic compiler I'm writing in Haskell. One of the requirements is that any character enclosed in single quotes (') is translated into a character literal token (type T_Char), and this includes escape sequences such as '\n' and '\t'. I've defined this part of the scanner function which works okay for m...
Hi I started learning scala a few days back and when learning it, I am comparing it with other FP languages like (Haskell, Erlang) which I had some familiarity with. My Question is Does Scala has Guard sequences available, I went through pattern matching in Scala but is there any concept equivalent to Guards with otherwise and all?
...
I'm hoping to use either Haskell or OCaml on a new project because R is too slow. I need to be able to use support vectory machines, ideally separating out each execution to run in parallel. I want to use a functional language and I have the feeling that these two are the best so far as performance and elegance are concerned (I like Cl...
I want to convert a Haskell Float to a String that contains the 32-bit hexadecimal representation of the float in standard IEEE format. I can't seem to find a package that will do this for me. Does anybody know of one?
I've noticed that GHC.Float offers a function to decompose a Float into its signed base and exponent (decodeFloat), but...
I am attempting to fix the size of a widget in GTK+, specifically using Gtk2hs with Haskell.
I have drawn an image in a DrawingArea and I would like to specify the exact size of this drawing area. I do not want other widgets or the user to make this widget larger or smaller. Is this possible?
Note, I am using ghc version 6.10.4 under U...
I'm Having problems understanding functors, specifically what a concrete type is in LYAH. I believe this is because I don't understand what [] really is.
fmap :: (a -> b) -> f a -> f b
Is [], a type-constructor? Or, is it a value constructor?
What does it mean to have the type of: [] :: [a]?
Is it like Maybe type-constructor, or Ju...
Consider the following Erlang code:
-module(testit).
-export([testit/0]).
testit() ->
Pid = spawn(fun testit_proc/0),
Pid ! final,
Pid ! one,
Pid ! two,
io:format("Root finished~n").
testit_proc() ->
receive
one -> io:format("One~n");
two -> io:format("Two~n")
end,
receive
...
The Control.Exception documentation says I can do the following to create my own exception:
data MyException = ThisException | ThatException
deriving (Show, Typeable)
instance Exception MyException
If I paste this into a file and compile (after importing Control.Exception and Data.Typeable), I get:
exp.hs:6:20:
Can't make...
If you look at the example for catches:
f = expr `catches` [Handler (\ (ex :: ArithException) -> handleArith ex),
Handler (\ (ex :: IOException) -> handleIO ex)]
It looks like catches has defined a custom mechanism to match on patterns (the two exception types). Am I mistaken, or can this be generalized to ...
How to define this class in scala
data NestedList a = Elem a | List [NestedList a]
This in Haskell means a NestedList is a Type which can contain either Elem or another NestedList. Is it possible to do these kind of recursive definitions in scala?
Actually this is what I am trying to acheive
Check Problem 7 here in this page.
Update...
Hi,
We'd like to serialize data in a specific binary format. We use Data.ByteStrings internally.
So, the question is: How to convert the different data types we use to a ByteString. For String we have no problem, we can use encodeLazyByteString UTF8 "string". But we'd also like to convert Integers to ByteStrings (big-endian).
Does any...
It is a wonderful, very fast, mature and complete language. It exists for a very long time and has a big set of libraries. Yet, it appears not to be widely used. Why ? I suspect it is because it is pretty rough and unforgiving for beginners, and maybe because its lazy execution makes it even harder
...
Erlang's got its multi-process debugger that let's you see all your processes. Anything similar in Haskell?
...
This works:
data Wrapped a = Wrapped a
alpha :: IO s -> IO ()
alpha x = do
rv <- wrapit x
return ()
where
wrapit :: IO s -> IO (Wrapped s)
wrapit x' = do
a <- x'
return (Wrapped a)
This doesn't:
data Wrapped a = Wrapped a
alpha :: IO s -> IO ()
alpha x = do
rv <- wrapi...
I'm trying a little experiment in haskell, wondering if it is possible to exploit laziness to process IO. I'd like to write a function that takes a String (a list of Chars) and produces a string, lazily. I would like then to be abily to lazily feed it characters from IO, so each character would be processed as soon as it was available, a...
I've been exploring the Stack Overflow data dumps and thus far taking advantage of the friendly XML and “parsing” with regular expressions. My attempts with various Haskell XML libraries to find the first post in document-order by a particular user all ran into nasty thrashing.
TagSoup
import Control.Monad
import Text.HTML.TagSoup
use...