Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [haskell]

A functional programming language

0
votes
2answers
86 views

In which way Haskell limit side effects?

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.
1
vote
3answers
166 views

In Haskell, is it a “violation” of functional programming to interact with something that was not a function parameter?

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 ...
0
votes
1answer
105 views

In what other locations besides infinite streams and infinite lists is memoized lazyness useful?

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 ...
1
vote
2answers
286 views

Patterns for tracking state in recursive Haskell code

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: ...
1
vote
1answer
82 views

Improving my inelegant Haskell deduplication function

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 ...
5
votes
0answers
99 views

Why does GHC represent recursion in Haskell with recursive binders instead of a fixpoint operator?

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 ...
2
votes
2answers
162 views

Is writing arithmetic functions to allow “type coercion” a good idea?

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 ...
2
votes
1answer
99 views

Dynamic *dll substitution?

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 ...
5
votes
3answers
243 views

Can referential transparency be assumed when dealing with floating-point arithmetic?

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 ...
7
votes
1answer
317 views

How does one reason about algorithmic complexity in Haskell?

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 ...
2
votes
4answers
546 views

What is the benefit of short readable code if you only see functions and classes on the outside?

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 ...
1
vote
0answers
74 views

How Functional Programming addresses concurrent increment/decrement operations invoked by different users? [duplicate]

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 ...
0
votes
2answers
353 views

How Functional Programming addresses concurrent increment/decrement operations invoked by different users?

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 ...
35
votes
6answers
6k views

What are the functional equivalents of imperative break statements and other loop checks?

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(...
2
votes
3answers
521 views

Can functional programming used for solving problems which require randomness?

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 ...
7
votes
1answer
457 views

What is the reasoning behind making non-determinism a feature of Haskell?

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 ...
11
votes
1answer
348 views

What are some intuitions that support calling the Maybe constructor in Haskell “Just”?

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 ...
1
vote
2answers
211 views

How is it obvious that that (foldr Cons Nil) just copies a list?

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 ...
7
votes
1answer
226 views

Should I use functions based on Applicatives or Monads?

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 ...
1
vote
1answer
208 views

How to automate Id generation?

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 ...
1
vote
1answer
81 views

Memoization of interdependent haskell functions

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 ...
0
votes
1answer
100 views

Memoization in case of recursive interdefined functions in Haskell/Functional Programming?

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 = ...
7
votes
3answers
410 views

How is arrow operator an Applicative Functor in Haskell?

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 = (\...
5
votes
3answers
447 views

Better way of logging than manual calls to a logging function?

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 "...
7
votes
1answer
195 views

IO Monadic code: standard vs flipped function composition

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 "...
4
votes
1answer
210 views

What are some practical uses of Generalized Algebraic Datatypes? [closed]

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 ...
2
votes
1answer
424 views

CQRS/ES in haskell, using “Out of the tar pit” paper architecture

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 ...
3
votes
2answers
200 views

how to model ADN & ARN in haskell?

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 ...
8
votes
3answers
797 views

What is the difference between Haskell's type classes and Go's interfaces?

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 ...
2
votes
2answers
236 views

How does Haskell decide which memoized value will be discarded?

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 ...
4
votes
1answer
315 views

Can variables be treated as constants in Haskell?

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 ...
12
votes
1answer
496 views

Is it possible to prove a function is idempotent?

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 ...
2
votes
2answers
371 views

Concerns on lazy evaluation and infinite data structures

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 ...
2
votes
3answers
498 views

What is a Haskell value

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 ...
0
votes
1answer
156 views

Are Foldable and Traversable replacement for Uniplate?

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 ...
0
votes
1answer
671 views

What is the difference between Applicative and Generative Modules, and Type Classes?

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-...
7
votes
2answers
395 views

Movable object design in Haskell

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 ...
0
votes
2answers
897 views

Implementing map with tail recursion

I am trying to solve this exercise. It is about reimplementing the map function in haskell for learning purpose. I found a solution which doesn't browse all the elements of the list (simple linked ...
3
votes
1answer
312 views

Between Applicative Functor and Monad

Is it possible to design an Applicative Functor with a few extra stack manipulation functions push, pop, and a specialized branching function ifA :: forall a. f Boolean -> f a -> f a -> f a, ...
1
vote
2answers
346 views

Do any languages other than Haskell implement strings as linked lists of characters?

Haskell’s String type is an alias for [Char] (i.e. a linked list of Chars). Does any other language use an implementation of strings like this?
6
votes
2answers
226 views

Casting a nullary data constructor between types

Suppose I have a parametrized data type with more than one nullary (constant) data constructor, such as: data Check a = Valid | Invalid | Unsure a Sometimes I want to manipulate the non-constant ...
3
votes
2answers
133 views

Implementing a key-sensitive monad bind for key-value Map

Based on the List monad I set out to define Monad instances for the Map type from Data.Map, to perform chained unions and folds on Maps like lists, but with the efficient sorting and merging of Maps: ...
1
vote
2answers
114 views

Type of map for Try[T]

I was looking at the type of map for Try[T] in Scala, which is: def map[S](f: T=>S): Try[S] From Haskell, I am used to the type of map being: map :: (a->b)->[a]->[b] This seems very ...
2
votes
1answer
243 views

What are the limitations of Java exception approach to errors?

Please ignore performance issues, I am interesting in data flow, safety, modelling, reasoning. I wonder what are the limitations of exception approach to error reporting implemented like in Java ...
7
votes
3answers
360 views

Dealing with (the risks of) infinite sequences in Haskell

I'm a couple of weeks into dabbling with haskell and I've made a pretty big dent in Learn You A Haskell. I feel like many of the type classes and common implementations up to applicatives and monads ...
5
votes
0answers
641 views

Event driven programming in Haskell

I'm new to Haskell, so this is more a high-level conceptual question. I've read this: https://wiki.haskell.org/Real_World_Applications/Event_Driven_Applications and it has this: run :: Domain -> [...
3
votes
2answers
334 views

Can a function be polymorphic and overloaded?

In Graham Hutton's book "Programming in Haskell", he defines a function to be polymorphic, if its type "contains one or more type variables". He then defines a function to be overloaded, if its type "...
22
votes
1answer
2k views

Could Hindley-Milner inference work for the Go language?

I've read that Hindley-Milner does not work with type systems that have subclasses, and there are other type system features that also do not work well with it. Go currently has only very limited type ...
6
votes
2answers
682 views

Why isn't Bounded a subclass of Enum in Haskell

It seems like any Bounded instance should have a sane implementation of Enum. I cannot personally think of a counterexample, although if someone comes up with one that isn't pathological then I will ...
2
votes
1answer
655 views

Difference between Python classes and Haskell typeclasses

I'm an intermediate Python dev and just starting out with Haskell. It seems like Python's classes can be used in a way that is similar to how Haskell's typeclasses are used. It seems like typeclasses ...