Skip to main content

Questions tagged [haskell]

A functional programming language

Filter by
Sorted by
Tagged with
0 votes
0 answers
727 views

The traditional (Scheme, Pascal) way to structure code is this: declare outer function declare inner function body of inner function body of outer function The where clause in Haskell moves ...
ceving's user avatar
  • 401
1 vote
0 answers
84 views

I wrote a java call graph generator with tree sitter (the 3rd-party library in question)'s python binding. I am doing a thought experiment on how I might model the same application in Haskell. I am ...
Acy's user avatar
  • 111
1 vote
1 answer
367 views

I have recently given Haskell another go, mostly because I heard about the book Haskell from first principles and so far I'm having a blast. My background is that of a mathematician mostly working in ...
J. Becker's user avatar
  • 119
6 votes
1 answer
530 views

I'm writing a parser for a markup language in haskell, and a finite state machine fell out of my ideal API. I have code that looks a bit like this: Token = BoldWord String | Word String | ...
user avatar
31 votes
3 answers
6k views

I'm trying to understand whether the Haskell and C++ communities mean different things by the word "functor", or if there's some underlying concept that unifies the two meanings. My ...
Stephen Warren's user avatar
0 votes
2 answers
239 views

The Elm Guide says to use Maybe for partial functions, but I was under the impression that returning Maybe solves the problem of partial functions and makes them total. It gives a value from the ...
bcb's user avatar
  • 119
0 votes
1 answer
184 views

Would it be (mostly) correct to say that the following are the parallels to the Haskell Monad operations in the imperative world? Monad's >> ~ C/C++/JavaScript/etc. , operator do expressions ~ C/...
P Varga's user avatar
  • 339
9 votes
4 answers
5k views

I'm a .Net and Angular developer who's been working with OO languages throughout my education and work history. Lately I've been thinking about spending some time with one of the functional ...
human17's user avatar
  • 425
0 votes
1 answer
258 views

So, I was wondering about how Haskell's lists are implemented. I looked it up, and found this: data [] a = [] | a : [a] So I get that you can write lists like this if you want to: a:b:c:[] -- ...
InfiniteDonuts's user avatar
3 votes
3 answers
269 views

I am not sure if I ever clearly understood standard corollary "what to solve" and "how to solve" used to point out difference between functional (declarative) and imperative programming paradigm ...
rahulaga-msft's user avatar
-3 votes
2 answers
178 views

Let's say, that we keep track of students entering the auditorium using their IDs(Key) and their check-in time(Value) in a Map. We delete the entries once they move out of the auditorium. I want to ...
Vicky's user avatar
  • 399
6 votes
1 answer
763 views

AFAIK in Haskell it is heavily recommended to avoid partial functions; and if these seem unavoidable (eg head) then return a Maybe. At least, so the Haskell wiki says 1 2 What's the use of the ...
gaazkam's user avatar
  • 4,549
2 votes
1 answer
341 views

I'd like to hear some pros and cons about where it's best to put Haskell typeclass instances. I identify 2 possible cases and can not decide for myself which one is best: Put the instances together ...
Petras Purlys's user avatar
0 votes
3 answers
744 views

From what I gathered from learning Haskell, functional programming limits the amount of side effects, but in what ways? Hope someone can enlighten me on this one.
user3489985's user avatar
1 vote
4 answers
517 views

I'm sure this must have been asked before, but I can't find anywhere that actually answers my question, so apologies if I have simply overlooked this. I am currently learning Haskell, and loving the ...
Raiden616's user avatar
  • 141
0 votes
1 answer
221 views

Haskell is one of the few non-strict languages out there. In his paper Why Functional Programming Matters, John Hughes uses (memoized) lazy evaluation (as well as higher-order functions) to implement ...
Qqwy's user avatar
  • 4,957
2 votes
2 answers
2k views

A frequent pattern in my Haskell code is element-wise recursion for transformation of a list with some carried state generated using the data in the list. Usually, this looks something like this: ...
TheEnvironmentalist's user avatar
1 vote
1 answer
259 views

I'm working on learning Haskell, and one of the simple exercises I put myself through to this end is writing a function that deduplicates a list, removing all of the duplicate elements of a list such ...
TheEnvironmentalist's user avatar
12 votes
1 answer
396 views

GHC's Core data type represents recursion with recursive binders in the Let constructor; as I understand it, all let expressions in Haskell are effectively let rec expressions. Why does GHC use this ...
DylanSp's user avatar
  • 327
2 votes
2 answers
229 views

Let's say I want to write a function to compute factorials of nonnegative integers. I could write something like this: fact :: Num a => Int -> a fact n = fromInteger(product [1..n]) (Let's not ...
Daniel McLaury's user avatar
2 votes
1 answer
161 views

I got an architectural problem here. Let say there is an IShell. It mainly responsible to map user's commands (represented as a linux-like strings) to an appropriate IExecutable's. Those ...
Zazaeil's user avatar
  • 345
6 votes
3 answers
435 views

A pure function is assumed to produce the same outputs given the same inputs. Suppose an (otherwise) side-effects free function computes with floating-point numbers. Due to numerical error, these ...
schrödingcöder's user avatar
8 votes
1 answer
1k views

In Haskell, lazy evaluation can often be used to perform efficient calculations of expressions that are written in a clear and concise manner. However, it seems that the language itself does not ...
Weston Markham's user avatar
2 votes
4 answers
841 views

Last years I made myself familiar with Python and Haskell. I am surprised and impressed about the short and readable code you can write in these 2 languages, especially in comparison to languages like ...
Elmex80s's user avatar
  • 155
1 vote
0 answers
88 views

Using Functional language, How can 2 different parties achieve the result of increment/decrement operations concurrently? For the below scenario, Let's say, I've 2 quantities in stock and 2 users in ...
Vicky's user avatar
  • 399
1 vote
2 answers
951 views

Using Functional language, How can 2 different parties achieve the result of increment/decrement operations concurrently? For the below scenario, Let's say, I've 2 quantities in stock and 2 users in ...
Vicky's user avatar
  • 399
37 votes
7 answers
9k views

Let's say, I've the below logic. How to write that in Functional Programming? public int doSomeCalc(int[] array) { int answer = 0; if(array!=null) { for(...
Vicky's user avatar
  • 399
2 votes
3 answers
1k views

This older question tells us that in functional programming "true" randomness cannot be achieved since in FP functions are pure/idempotent and return the same value irrespective of number of ...
Vicky's user avatar
  • 399
8 votes
1 answer
2k views

We know that in Prolog - non-deterministic predicates are a feature used to whittle down combinatorial problems. In Haskell we see some similar non-deterministic behaviour to Prolog in the List ...
hawkeye's user avatar
  • 4,849
12 votes
1 answer
593 views

The intuition of an optional type like Maybe Int is that either there is no Int (thus, there's Nothing there) or that there is some Int; there is something there. It makes sense to me that we call the ...
vijrox's user avatar
  • 276
1 vote
2 answers
461 views

I am currently reading Why Functional Programming Matters by John Hughes. In the "Gluing Functions Together" section, after having explained that (foldr f a) is a function that replaces all ...
nich's user avatar
  • 27
9 votes
1 answer
899 views

There are a lot of functions that accomplish the same thing, but using Applicative vs Monad definitions. Some examples are: (<*>) vs ap pure vs return (*>) vs (>>) traverse vs mapM ...
zbw's user avatar
  • 201
1 vote
1 answer
471 views

I'm working on yesod application which has routes like /make/something MakeR POST on which server generates an object and returns its ID wrapped into JSON. I use Int as ID. So, I ended up using a ...
user avatar
1 vote
1 answer
149 views

I have three functions which act on a matrix and kind of find a minimum sum path (Note dim = 80, See https://projecteuler.net/problem=82): -- f is the minimum cost from x, y by taking only up and ...
RE60K's user avatar
  • 267
0 votes
1 answer
233 views

I was reading Memoization with recursion which tells how for a recursively defined function fun we can do memoization by: -- Memoization memoize f = (map f [0 ..] !!) -- Base cases g f 0 = 0 g f 1 = ...
RE60K's user avatar
  • 267
7 votes
3 answers
1k views

Note: Still learning Haskell, not reached Monoids, studying Applicative Functors. I saw this implementation and I am not entirely clear on it: instance Applicative ((->) r) where pure x = (\...
RE60K's user avatar
  • 267
6 votes
3 answers
762 views

I'm writing a simple web server in Haskell, and putting in a bit of logging. I've got some calls to a logging function in a chain of IO >>=. It all feels a bit manual. Is there a better/more "...
Michal Charemza's user avatar
8 votes
1 answer
331 views

Below is a line that handles socket connections in a simple Haskell program. mainLoop :: Socket -> IO () mainLoop sock = accept sock >>= forkIO . handle . fst >> mainLoop sock The "...
Michal Charemza's user avatar
4 votes
1 answer
493 views

All tutorials on GADTs that I've seen (in Haskell, Coq and Idris) use one same exapmle of a well-typed interpreter to show how GADTs can be useful, where you use the type index to encode the type of ...
Alex's user avatar
  • 284
3 votes
1 answer
865 views

I find it difficult allying CQRS/ES with the "Out of tar pit" paper architecture. This architecture implies 4 layers: State (state of the application) Business Domain (purely functional) I/O Control ...
Stephane Rolland's user avatar
2 votes
2 answers
304 views

I would like to modelize some nucleotid chains : ADN & ARN. ADN is a list of nucleotids : A,T,G,C. ARN is a list of nucleotids : A,U,G,C. ideally, I would like to define e.g. ADN as a list of ...
lolveley's user avatar
  • 131
11 votes
3 answers
2k views

I am wondering if there is a difference between Haskell's type classes and Go's interfaces. Both define types based on functions, in that way, that a value matches a type, if a function required by ...
ceving's user avatar
  • 401
2 votes
2 answers
591 views

Haskell keeps the computed values of functions. This can be done only up the the storage limit. When the storage limit is reached, how does Haskell decide which computations to keep and which to ...
ceving's user avatar
  • 401
5 votes
1 answer
1k views

This is an embarrassingly basic question, but until recently I have avoided properly understanding IO in Haskell and now I need to. I am writing (with someone else) a program that takes as part of ...
user15553's user avatar
  • 159
13 votes
1 answer
1k views

Is it possible to use static or dependent types to prove a function is idempotent? I've searched Google and various places on StackOverflow/StackExchange for the answer with no luck. The closest I've ...
bmaddy's user avatar
  • 241
2 votes
2 answers
716 views

I am trying to learn how lazy evaluation works because I'm going to implement try to implement it in the programming language I'm developing (I know it isn't the best thing to do (to try to implement ...
user6245072's user avatar
2 votes
3 answers
2k views

What is the meaning of the term "value" in statements such as: A Haskell function is a first-class value Every value has a type In both statements, I am left wondering what a value is and have a ...
S Thong's user avatar
  • 39
1 vote
1 answer
284 views

I have a kind of minimal language (sort of parser for CISCO-like CLI) that have parser described below. The parser should be serializable to JSON, that's why not Parsec or Attoparsec. I need a sort ...
voidlizard's user avatar
3 votes
1 answer
1k views

Reading the comments to this blog post made me realize I don't know much about some really interesting functional mechanisms between languages like Haskell, OCaml and Standard ML. I'd love a high-...
johnbakers's user avatar
6 votes
2 answers
596 views

Suppose I have an object which has a point denoting it's location and shape. type Point = (Double, Double) data Object = Object { location :: Point , shape :: Shape } where a shape ...
user avatar

1
2 3 4 5 6