Tagged Questions
6
votes
1answer
92 views
How to move a subtree between trees in Haskell?
For two multi-way trees, t1 and t2, defined using
type Forest a = [Tree a]
data Tree a = Node {
rootLabel :: a,
subForest :: Forest a
}
how can I write a function that ...
4
votes
2answers
69 views
Avoiding duplicates in breadth-first search
For educational purposes I've recently been implementing common algorithms in Haskell. Currently I'm stuck on Breadth-First Search. This is my implementation, with nodes being represented as just ...
0
votes
0answers
58 views
Dynamic call graphs in Haskell (or other higher order languages)
My question about dynamic call graphs is twofold:
First of all I am interested if there is any work that gives a definition for call graphs in higher order functional languages?
For example consider ...
1
vote
3answers
70 views
Partially applied List Comprehension
I'm starting to learn Haskell, and it turns out that there, you can make a list comprehension a partially applied function. In other words, it returns a function which accepts a list, and then runs ...
8
votes
0answers
154 views
Generalizing Haskell: could we replace Hask with Cat?
It is great that Haskell allows us to walk around in the category Hask. But sometimes I feel it is too tight. So I had this idea about a programming language that would allow us to move around in the ...
0
votes
2answers
77 views
Define min function using Foldr
I want to define min function to get minimum number on a list using Foldr function
min xs = foldr (\ x y -> if x<y then x else y) xs
Although I understand the logic of Foldr for simple ...
1
vote
2answers
69 views
Haskell expression validation on tuple
is this expression valid on Haskell ?
(1,2,\_ ->3 )
I think it's valid but it gives an error when try it on GHCI prelude
5
votes
1answer
93 views
IO Monad in Dynamicly-typed Languages
In Haskell, one of the things which I feel is quite beautiful is its use of Monads as an abstraction over effectful actions. It creates a really elegant way to express imperative code, while also ...
1
vote
1answer
60 views
Link two data types together in Haskell
I'm an absolutely beginner in Haskell.
I want to construct two data types like:
data A = A B
data B = B A
(With additional data in the objects of course)
I would like to create an object like ...
5
votes
0answers
110 views
A haskell Game of life crashes when launched
Helllo, i'm curently trying to develop a tiny Conway's Game of Life in haskell. I wrote a library, lifegame, that enables to manage a grid of cells and to compute it's generations
(see ...
0
votes
1answer
43 views
Accessing multiple data structures
I am writing a text-based adventure game in Haskell for experience after reading LYAH, but I need help writing a function in which two data structures (in this case two players) are accessed and ...
5
votes
3answers
168 views
Haskell type inference
When I play with checking types of functions in Haskell with :t, for example like those in my previous question, I tend to get results such as:
Eq a => a -> [a] -> Bool
(Ord a, Num a, Ord ...
4
votes
2answers
94 views
Understanding function types
I am getting a bit confused in my attempts to understand how Haskell determines function types. Here is an example:
boolFcn x y = x/=3 && y/=4
When I check the type of the above function, ...
2
votes
5answers
162 views
Why does Haskell allow a list of Shape, but no list of Square or Circle or Triangle
Why does Haskell allow to do a list of Shape as in the first exemple, but not as in the second example? As far as I know, both lists would have elements that are either
{ name :: String, position :: ...
3
votes
4answers
111 views
The Haskell RNG and state
As a Java person learning Haskell I was getting use to the new way of thinking about everything but I've spent half a day trying to implement something with a simple RNG and am getting nowhere. In ...
8
votes
3answers
150 views
Pure Lambda Calculus - and function
I am currently learning Haskell and also participating in a rather theoretical lecture about functional programming at university.
I know that this is purely theoretical/academic question, but ...
11
votes
3answers
695 views
What are some examples of type-level programming? [closed]
I do not understand what "type-level programming" means, nor can I find a suitable explanation using Google.
Could someone please provide an example that demonstrates type-level programming? ...
1
vote
3answers
83 views
Is an associative map or dictionary a functor?
I believe that it could be if we consider the values in the map as the values to consider in the functor and the keys as part of the context (I am pulling this language from
Typeclassopedia
) but I ...
2
votes
0answers
113 views
Combining the state monad with the costate comonad
How to combine the state monad S -> (A, S) with the costate comonad (E->A, E)?
I tried with both obvious combinations S -> ((E->A, E), S) and (E->S->(A, S), E) but then in either ...
3
votes
2answers
104 views
Haskell: Alternative to patterns of where f = foo e, e = bar d, d = baz c
I have a function which is growing and which is getting a where pattern like what is shown bellow. What is the proper alternative to these where f = fooed e which is equal to bared e which is equal to ...
1
vote
2answers
58 views
Haskell: Sum of the occurrences of each char from a string A in a string B
Say that I have two strings, how can I get the sum of the occurrences of each char in string A in string B?
For exemple, how can I know, in the string someString: the numbers of a + the numbers of b ...
1
vote
2answers
75 views
Determining the type of a function
I am trying to figure out the way Haskell determines type of a function. I wrote a sample code:
compareAndIncrease a b =
if a > b then a+1:b:[]
else a:b:[]
which constructs a list ...
1
vote
1answer
38 views
Getting parse error on input `=' error
import Data.Char (digitToInt)
let f [] = []
f ('\n':',':a) = f ('\n' : a)
f (a:b) = a : f b
main :: IO ()
main = do
ln<-getLine
f ln
print dp
getting parse error on ...
1
vote
2answers
117 views
Haskell: Call a function with each element in a list
I am making a sudoku solving program and I have a potentialNbrsAt function that gets the numbers that could be at position x y.
Now, I am trying to get the intersect of each lists of potential ...
5
votes
2answers
171 views
Haskell - understanding I/O monad
I am still struggling with Haskell and now I have encountered a problem with wrapping my mind around Input/Output monad from this example:
main = do
line <- getLine
if null line
then ...
13
votes
5answers
679 views
Difference between $ and ()
I started learning Haskell and I encountered a problem I can't just understand. I've got a method used to find value from a list of key-value list (from this page):
let findKey key xs = snd . head . ...
1
vote
2answers
72 views
Haskell: Change a list of 100 numbers to 10 lists of 10 numbers?
In Haskell, how does one change a list of x numbers into n lists of n numbers?
The first sublist would have numbers first to tenth, second list 11th to 20th...
myFunction :: [Int] -> [[Int]]
4
votes
4answers
263 views
Why doesn't Haskell have a stronger alternative to Eq?
The reason why Set is not a functor is given here. It seems to boil down to the fact that a == b && f a /= f b is possible. So, why doesn't Haskell have as standard an alternative to Eq, ...
1
vote
2answers
87 views
How to define and use global array in Haskell?
I am new in Haskell world. I have to create a game based on checkers board and would like to define global variable - an array representing board. Do you know how to define this array and use it ...
0
votes
1answer
81 views
Haskell function type not what expected [closed]
I am trying to write a function to compute the inner product of 2 lists, i.e. if the lists are [1,2,3] and [4,5,6] then the inner product would be (1 x 4) + (2 x 5) + (3 x 6) = 4 + 10 + 18 = 32.
So I ...
18
votes
6answers
2k views
What do you call the data wrapped inside a monad?
In speech and writing, I keep wanting to refer to the data inside a monad, but I don't know what to call it.
For example, in Scala, the argument to the function passed to flatMap gets bound ...
1
vote
0answers
84 views
Heap Algorithmic Issue
I am having this algorithmic problem that I want to discuss about. Its not
about find a solution but about optimization in terms of runtime. So here it is:
Suppose we have a race court of ...
0
votes
1answer
62 views
Haskell Selective Text Obfuscation
I would like to obfuscate a text file report without obscuring certain keywords, like report titles, column headers, etc. I've built such a program using newLisp. I'm trying to implement the ...
1
vote
2answers
69 views
Lazy filter with multi param function in haskell
I'm writing a function that remove white space in a json string. I
need to know if the current char I'm processing is surrounded by ", or
if it is after a escape char \. So I need two more param for ...
2
votes
2answers
79 views
Is there a way in haskell to express a point free function to edit the property of a data type?
I have the type:
data Cons = Cons {myprop :: String}
and later on I'm mapping over a list, setting the property to a different value:
fmap (\x -> x{myprop = ""}) mylist
Is there a point free way ...
3
votes
0answers
87 views
Relation between object [closed]
For a few weeks I’ve been thinking about relation between objects – not especially OOP’s objects. For instance in C++, we’re used to representing that by layering pointers or container of pointers in ...
14
votes
0answers
397 views
Precise flow control in Haskell
The Idea
Hello! I'm trying to implement in Haskell an image processing library based on dataflow ideology. I've got a problem connected to how I want to handle the flow of control.
The main idea is ...
1
vote
1answer
135 views
How IO operations working on F#
There were IO monad on haskell to keep it pure. I know f#/ocaml supports mutable state but how IO operations works actually. What is corresponding concept to haskell's IO monad.
0
votes
0answers
93 views
Haskell replace paranthesis in string with it's result -> have almost all functions
Hi I am trying to make a parser for normal calculations that recognizes + - \ * ^(pow) and %(mod) and I have almost everything employed except I need one more thing, to replace the first most interior ...
1
vote
0answers
59 views
Names of monadic functions [duplicate]
I'm reading about monads and every tutorial shows functions >>=, >>, <$>, <*>. But do they have some english name? i want to be able to talk about them, not only to write
6
votes
4answers
156 views
Is there a way to avoid copying the whole search path of a binary tree on insert?
I've just started working my way through Okasaki's Purely Functional Data Structures, but have been doing things in Haskell rather than Standard ML. However, I've come across an early exercise (2.5) ...
4
votes
2answers
153 views
How to write clear code with logging?
logging is cluttering my "beautiful" clean simple short code.
instead of a simple
def mymethod = dosomething // scala
my code is also having also all these nasty logging statements which and ...
1
vote
2answers
116 views
haskell if true then break or continue loop
I am fairly new to Haskell.
I want to pass two items:
First a list of numbers as strings say ["1","2","3","4"] and I want to see if each of these items appears in random string of numbers say ...
1
vote
1answer
65 views
I_AMAX in Haskell and other Programming Languages — RANGE
Is there a concept of range in Haskell or other functional programming languages? Suppose I want to compute I_AMAX from BLAS (to find the smallest index of the largest element in vector x). A naive ...
2
votes
2answers
64 views
Using netwire's periodic vs. at wires
I'm trying to write a framework for real-time interactive graphics in Haskell. I've been trying to get a handle on things by using Netwire 5, but I don't seem to have a good handle on how things ...
0
votes
4answers
159 views
Programming style in OCaml
I have a question about the correct way to write efficient functional programs. Suppose I'm given a list s of positive ints, and I want to find the minimum element (or just 0 if empty). Then a generic ...
4
votes
2answers
129 views
Using Numeric.Integration.TanhSinh for N-dimensional integration
I am using Numeric.Integration.TanhSinh for numerical integration in Haskell. This defines a function
parTrap :: (Double -> Double) -> Double -> Double -> [Result]
where the first ...
3
votes
2answers
85 views
Chaining values with catamorphisms
Suppose I have definitions as follows (where cata is the catamorphism):
type Algebra f a = f a -> a
newtype Fix f = Fx (f (Fix f))
unFix :: Fix f -> f (Fix f)
unFix (Fx x) = x
cata :: ...
8
votes
1answer
210 views
Do the functor laws prove complete preservation of structure?
In the documenation for Data.Functor the following two are stated as the functor laws, which all functors should adhere to.
fmap id == id
fmap (f . g) == fmap f . fmap g
The way my intuition ...
0
votes
1answer
87 views
What is a functional way to accumulate values from callback into a list?
I'm interoping with a C function that I pass a (callback) function to and it calls it every-time with a different parameter.
I imported it into Haskell and now I have something like this (I've ...