I have these two Haskell data types:
data Code
= Code_A | Code_B | Code C
deriving (Eq,Show)
data ListObject = Code | Int
I need to make a list that contains ListObjects. That is both integer values and codes ([1,2, Code_A, 3]). I know it should be possible but I just can't figure the syntax for it. Haskell can do some neat ...
I would ideally like to write something like this:
myValue1 = 1 :: Int
myValue2 = 2 :: Int
myFunc :: Int -> Bool
myFunc myValue1 = True
myFunc myValue2 = False
Calling 'myFunc myValue2' returns True - not what I intend. I know why this happens, but is there a way to express this in Haskell without resorting to C-style '#define' stat...
Given a sequence of char what is the most efficient way to find the first non repeating char
Interested purely functional implementation haskell or F# preffered.
...
I find myself running into a problem commonly, when writing larger programs in Haskell. I find myself often wanting multiple distinct types that share an internal representation and several core operations.
There are two relatively obvious approaches to solving this problem.
One is using a type class and the GeneralizedNewtypeDeriving...
So I was playing around with Haskell today, thinking about autogeneration of function definitions given a type.
For example, the definition of the function
twoply :: (a -> b, a -> c) -> a -> (b, c)
is obvious to me given the type (if I rule out use of undefined :: a).
So then I came up with the following:
¢ :: a -> (a ->b) -> b
¢ =...
Hi
I wrote a Haskell code which has to solve the following problem : we have n files : f1, f2, f3 .... fn and I cut those files such a way that each slice has 100 lines
f1_1, f1_2, f1_3 .... f1_m
f2_1, f2_2, .... f2_n
...
fn_1, fn_2, .... fn_k
finally I construct a special data type (Dags) using slices in the following way
...
How can I clear WinGhci's (one of Haskell's Windows IDEs) command prompt and all the current "session" values?
...
I must compile on a recent version of Haskell a software written for a previous version of the standard libraries. The code assumes Data.Map.lookup has type:
lookup :: (Monad m, Ord k) => k -> Map k a -> m a
as it was the case with e.g. GHC 6.8.1/containers 0.1.0.0., but since (at least) GHC 6.10.1/containers 0.2.0.0 Data.Map.lookup h...
This function generates simple .dot files for visualizing automata transition functions using Graphviz. It's primary purpose is debugging large sets of automatically generated transitions (e.g., the inflections of Latin verbs).
prepGraph :: ( ... ) => NFA c b a -> [String]
prepGraph nfa = "digraph finite_state_machine {"
:...
Let's say I want to know all the points on a (x, y) plane that are in the rectangle has.
I can calculate that using List Comprehensions, this way:
let myFun2D = [(x, y) | x <- [0..2], y <- [0..2]]
Now, if I want to accomplish the same for a (x, y, z) space, I can go the same way and do:
let myFun3D = [(x, y, z) | x <- [0..2], y <- [...
I've been reading about Haskell and I'm having a hard time understanding how function definitions are handled in this language.
Let's say I'm defining a sum function:
let sum x y = x + y
if I query Haskell for its type
:t sum
I get
sum :: (Num a) => a -> a -> a
What does it mean the => operator? Does it have anything to do wit...
With WinGHCi, how can one implement the following code?
soma :: Int -> Int
soma 1 = aluno 1
soma n = aluno n + soma (n-1)
I am currently writing multiline code using
:{
...
:}
but that doesn't seem to solve the issue, in this case.
Also, why doesn't something as
soma x y = x + y
work, when I'm working in WinGHCi? I can only do i...
I'm trying to simulate a bouncing ball with the Yampa-Framework: Given an initial x-position, height and velocity, the ball should bounce according to gravity rules. The signal function takes a "Tip-Event" as input, the idea being "when the ball is tipped, it's speed should double".
The ball bounces nicely, but every time there is a tip...
I'm a Haskell beginner and thought this would be good exercise. I have an
assignment where I need to read file in a thread A, handle the file lines
in threads B_i, and then output the results in thread C.
I have implemented this far already, but one of the requirements is that we
cannot trust that the entire file fits into memory. I wa...
Trying to make a very simple boolean function that will find whether a line intersects a sphere.
This did not seem to be what I want, even though the question was similar:
http://stackoverflow.com/questions/910565/intersection-of-a-line-and-a-sphere
Also I have tried the algorithms listed at:
http://www.docstoc.com/docs/7747820/Inters...
So i am given this
intCMP :: Int -> Int -> Ordering
intCMP a b | a == b = EQ
| a < b = LT
| otherwise = GT
intCMPRev :: Int -> Int -> Ordering
intCMPRev a b | a == b = EQ
| a < b = GT
| otherwise = LT
floatCMP :: Float -> Float -> Ordering
floatCMP a b | a == b = EQ
| a < b = LT
| otherwise = GT
...
When reading Wikipedia's entry on Haskell 2010 I stumbled across this:
-- using only prefix notation and n+k-patterns (no longer allowed in Haskell 2010)
factorial 0 = 1
factorial (n+1) = (*) (n+1) (factorial n)
What do they mean by "n+k patterns"? I guess its the second line, but I don't get what might be wrong with it. Could any one...
I know this question may sound silly, but I am learning (at least trying) Haskell for about 4 days. I've already finished to read http://learnyouahaskell.com/, and now I am investing time in: The Haskell Road to Logic, Math and Programming, and things got really complicated for me. I don't have experience in functional programming, just ...
Is there a library function to put commas into numbers with Haskell? I can't find one for the life of me.
I want a function that would work something like this:
format 1000000 = "1,000,000"
format 1045.31 = "1,045.31"
but I can't seem to find any number formatting functions of this type in Haskell. Where are the number formatting fun...
I'm a Haskell newbie, and I'm trying to get the wai package working (because I'm interested in using Haskell for web applications). I tried to start with the first, simplest example from the wai homepage:
[ 1] {-# LANGUAGE OverloadedStrings #-}
[ 2] import Network.Wai
[ 3] import Network.Wai.Enumerator (fromLBS)
[ 4] import Network.Wai....