Im a student who is really new to functional programming. Im working on a banking application where the data has been already defined as,
type Accountno = Int
data Accounttype = Saving | Current | FixedDeposit deriving (Show,Read)
type Accountamount = Int
type Name = String
type Account = (Accountno, Name, Accounttype, Accountamount)...
I'd like to see if it is feasible to have a type class for converting one thing into another and back again from a mapping of [(a,b)].
This example should illustrate what I'd like to do:
data XX = One | Two | Three deriving (Show, Eq)
data YY = Eno | Owt | Eerht deriving (Show, Eq)
instance Convert XX YY where
mapping = [(One, Eno)...
Given a data type
data Foo =
Foo1 { foo1Name :: String}
| Foo2 { foo2Name :: String, foo2Age :: Integer }
I would like to be able to extract the Data.Data.DataTypeS of Foo1 and Foo2s fields.
I tried
datatype = (undefined :: Foo)
constrs = dataTypeConstrs datatype
foo1 = fromConstrs (head constrs) :: Foo
foo1Fields = gmapQ dataT...
I have a function, which creates some random numerical results. I know, that the result will be an integer in a (small, a - b approx 50) range a, b. I want to create a function which execute the above function let's say 1000000 times and calculates, how often the each result appears. (The function takes a random generator to produce the ...
If I create a module AModule with a typeclass Foo,
module AModule where
class Foo a where
bar :: a
and in another module BModule import AModule qualified and try to make some type an instance of Foo, i.e.
module B where
import qualified AModule as A
instance A.Foo Int where
A.bar = 0
GHC tells me "Qualified name in binding po...
I started reading about GADT in Haskell Wiki but didn't feel quite comfortable understanding it. Do you recommend a specific book chapter or a blog post explaining GADT for a Haskell beginner?
...
Hello, i have this
module Main where
import Control.Parallel(par,pseq)
import Text.Printf
import Control.Exception
import System.CPUTime
import Data.List
import IO
import Data.Char
import Control.DeepSeq
time :: IO t -> IO t
time a = do
start <- getCPUTime
v <- a
end <- getCPUTime
let diff = (fromIntegral (end - start)) / ...
In high-performance computing, sums, products, etc are often calculated using a "parallel reduction" that takes n elements and completes in O(log n) time (given enough parallelism). In Haskell, we usually use a fold for this kind of calculation, but evaluation time is always linear in the length of the list.
Data Parallel Haskell has so...
For a description of the data structure see
http://www.flipcode.com/archives/The_Half-Edge_Data_Structure.shtml
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/HalfedgeDS/Chapter_main.html
An half-edge data structure involves cycles.
is it possible to implement it in a functional language like Haskell ?
are mutable reference...
In Haskell, is it possible to write a function with a signature that can accept two different (although similar) data types, and operate differently depending on what type is passed in?
An example might make my question clearer. If I have a function named myFunction, and two types named MyTypeA and MyTypeB, can I define myFunction so th...
I'm having some problems with HXT, though I suspect it's just something I'm missing about arrows.
I have an XML structure like
<str name="field1">value</str>
<lst name="field2"><str>value2</str><str>value3</str></lst>
And internal structure like
data XmlData = XmlStr String | XmlList XmlData
Is there a way to collect elements at a...
I read the documentation and some articles that talk about the package, but I'm new to Haskell and did not understand much but I tried ....
Below is what I did:
module Main where
{-# LANGUAGE BangPatterns #-}
import Control.Parallel(par,pseq)
import Control.Exception
import Data.List
import IO
import Data.Char
impor...
I'm trying to translate the Haskell core library's Arrows into F# (I think it's a good exercise to understanding Arrows and F# better, and I might be able to use them in a project I'm working on.) However, a direct translation isn't possible due to the difference in paradigms. Haskell uses type-classes to express this stuff, but I'm no...
Hi my Xmonad has been working perfectly until few days ago, then I think I installed something with Synaptic and then started to complain about Xmonad.Config.Gnome
here it is my xmonad.hs
import XMonad
import XMonad.Config.Gnome
myManageHook = composeAll [
(className =? "Pidgin" <&&> title =? "Buddy List") --> doFloat
...
Hi. Hopefully some of you can help me clear up this confusion I have. I'm sorry for the bad title - if anyone has suggestions I'll change it.
Let's set up some context first. I've reduced everything down to the essentials, so bear with me if the example code below is somewhat contrived. Let's say we have
class Foo a where
foo :: a
...
Is there an IO action that gives me the number of OS threads the RTS was initialized with? It would be nice to be able to use this as an argument to the parBuffer function from the Control.Parallel.Strategies module.
...
I am trying to learn pure functional programming language like Haskell as I am from Perl background and read that Perl can also implement functional programming techniques. So few qusetions came in mind:
Whether it is worth doing it in Perl 5? Does Perl 6 will make a difference?
Can anybody suggest some code/examples implementing functi...
maxZyklus :: UntereGrenze -> ObereGrenze -> (UntereGrenze,ObereGrenze,MaxZyklaenge)
maxZyklus m n = if m > n then (m,n,0) else if m == n then
(m,n,length(func m)
else
(m,n,length(func m)
type UntereGrenze = Integer
type ObereGrenze = Integer
type MaxZykLae...
Why does the following Haskell script not work as expected?
find :: Eq a => a -> [(a,b)] -> [b]
find k t = [v | (k,v) <- t]
Given find 'b' [('a',1),('b',2),('c',3),('b',4)], the interpreter returns [1,2,3,4] instead of [2,4]. The introduction of a new variable, below called u, is necessary to get this to work:
find :: Eq a => a -> [(...
I'm a haskell newbie, and having a bit of trouble figuring out how to pattern match a ByteString. The [Char] version of my function looks like:
dropAB :: String -> String
dropAB [] = []
dropAB (x:[]) = x:[]
dropAB (x:y:xs) = if x=='a' && y=='b'
then dropAB xs
else x:(dropAB $ y:xs)
As expec...