A functional programming language

learn more… | top users | synonyms

6
votes
0answers
80 views

Maintaining State without assignment

I am learning functional programming and I have trouble understanding how some particular scenarios are implemented without the use of assignment. The following simple problem pretty much sums up my ...
34
votes
7answers
13k views

Haskell AND Lisp vs. Haskell OR Lisp [on hold]

I currently code with C, C++, and Python. I'm wanting to pick up a functional programming language, and right now I'm leaning toward Haskell. I do NOT want to start a "Haskell vs Lisp" war here; what ...
56
votes
5answers
6k views

What exactly makes the Haskell type system so revered (vs say, Java)?

I'm starting to learn Haskell. I'm very new it and am just reading through a couple of the online books to get my head around its basic constructs. One of the 'memes' that people familiar with it ...
36
votes
1answer
3k views

Why (or why not) are existential types considered bad practice in functional programming?

What are some techniques I might use to consistently refactor code removing the reliance on existential types? Typically these are used to disqualify undesired constructions of your type as well as to ...
6
votes
2answers
301 views

Is it possible to “bake dimension into a type” in haskell?

Suppose I want to write a library that deals with vectors and matrices. Is it possible to bake the dimensions into the types, so that operations of incompatible dimensions generate an error at compile ...
0
votes
2answers
184 views

Missing `$` like operators in Haskell

Below I've produced what I believe to be a summary of the standard $ like operators for various classes in Haskell. There's some gaps however. Following the applicative pattern, you would think those ...
6
votes
0answers
134 views

Is it common practice to transform requirement specifications into predicate logic for functional programming?

I've recently been assigned to work on a small project which is being implemented in Haskell. Coming from an OO/imperative background, I'm used to converting requirements/user-stories into use-cases ...
4
votes
3answers
3k views

Why C# is not statically typed but F# and Haskell are?

There was a talk given by Brian Hurt about advantages and disadvantages of static typing. Brian said that by static typing he don't mean C#, but F# and Haskell. Is it because of dynamic keyword added ...
2
votes
2answers
391 views

What is the logic behind the use of different arrows (-> <-) in Haskell?

I've been thinking about language design lately, and reading over some of the new things in Haskell (always a nice source of inspiration). I'm struck by the many odd uses of the left <- and right ...
10
votes
0answers
192 views

Haskell build and artifact environment similar to Maven

I used to be a Java developer for a long time, but recently, I joined a Haskell team. In the java world, if you have a large project, with several teams working on it, a common approach is to use an ...
1
vote
1answer
115 views

Functional Programming style: How to write functions - explicit currying, implicit currying or lamdas?

So I have been using F# for a while and studying a bit of Haskell on the side and I have realized I could rewrite the exact same function one of three different ways. Either with implicit currying, ...
5
votes
2answers
460 views

Why isn't `length` generic by default?

Haskell often provides two versions of a given function f, i.e: f :: Int ... genericF :: Integral i => i ... There exist many standard library functions with those two versions: length, take, ...
1
vote
1answer
88 views

Is unifiing ADTs with typeclasses possible?

When i was thinking about language design i got an idea that ADTs (Aglebraic Data Types) and typeclasses could be the same thing. They can both represent a group of types, but in haskell they are not ...
-2
votes
2answers
133 views

haskell - are tuples defined recursively?

Are n-tuples defined recursively in terms of 2-tuples, for example, are (a,b,c) and (a,(b,c)) the same? If not, what's the rationale behind it?
2
votes
2answers
206 views

Does this Haskell pattern have a name?

I recently found use for the following Haskell functions: feed :: (a -> (a, b)) -> a -> Int -> (a, [b]) feed f input 0 = (input, []) feed f input n | n < 0 = error "feed f input n: n ...
3
votes
0answers
83 views

Using Haskell type classes to enforce commutativity

I want to define a type class for geometric objects that can be intersected together: class Intersect a b c | a b -> c where intersect :: a -> b -> c -- Language extensions: ...
2
votes
1answer
96 views

How to make an interpreter for a stack of Free Monad Transformers

I like the idea of using Free monads to "purify" code and I've used it in some simple scenarios. However, I can't seem to figure out how to write an interpreter for a Free monad transformer. In ...
3
votes
1answer
270 views

Does Clojure borrow concurrency ideas from Haskell?

In code quarterly interview with Rich Hickey, Michael Fogus hints that Clojure borrows a lot from Haskell: Fogus: As someone who only knows Haskell enough to read the papers, Clojure appears to ...
6
votes
1answer
160 views

Is the use of DSLs in a state monad a good approach to building complex stateful computations?

First, sorry if that title makes no sense. I am a little out of my depth here with the terminology. So, imagine that I'm writing a text editor in Haskell. For the purposes of this question, let's ...
19
votes
1answer
1k views

How often is seq used in Haskell production code?

I have some experience writing small tools in Haskell and I find it very intuitive to use, especially for writing filters (using interact) that process their standard input and pipe it to standard ...
1
vote
2answers
134 views

Is there a way to write this fold neater in Haskell?

I have the following small function that uses foldr to find the largest second number of a 2-tuple: listMax :: [(Int,Int)] -> Int listMax = snd . foldr (\(_,freq1) (_,freq2) -> (0,max freq1 ...
0
votes
4answers
206 views

Haskell's ':' operator

I am currently studying about pattern matching in Haskell from here. The author gives an example of the implementation of "head" function (which returns the first element of a list) as following: ...
15
votes
3answers
1k views

does haskell have dependent types?

I know Haskell already has the ability to parametrise a type over another type (similar to template programming in C++), but I'm wondering whether Haskell can also parametrise a type over values – ...
4
votes
4answers
2k views

How is CoffeeScript influenced by Haskell?

I've been using CoffeeScript for a while now. On Wikipedia, it is said that CoffeeScript is influenced by Haskell. But after I check out the syntax of Haskell, I have found little resemblance from ...
2
votes
0answers
279 views

Haskell, Rust, or D for POSIX shell implementation? [closed]

I am planning on writing my own Bourne shell. It will be full-featured, capable of being used as a system /bin/sh. The shell will be implemented very differently from other Bourne shells, however. ...
18
votes
8answers
3k views

Why is the concept of lazy evaluation useful?

It seems lazy evaluation of expressions can cause a programmer to lose control over the order in which their code is executed. I am having trouble understanding why this would be acceptable or desired ...
13
votes
1answer
464 views

What is Banana split and fusion in functional programming?

These terms got mentioned in my university course. Quick googling pointed me to some university papers, but I am looking for a simple explanation.
0
votes
1answer
163 views

Programming CPU Emulator Functional Style [closed]

I want to write an 8086 CPU emulator in javascript, functional style. How would one conceptualise / design an 8086 emulator, or any CPU emulator that has registers and realmode memory access in a ...
1
vote
4answers
4k views

Using foldr to append two lists together (Haskell)

I have been given the following question as part of a college assignment. Due to the module being very short, we are using only a subset of Haskell, without any of the syntactic sugar or idiomatic ...
3
votes
1answer
89 views

How should I setup this type to be intuitive?

I have the following types: data Bomb = TimedBomb { bPos :: Point, bPower :: Float, detTime :: Float } data Enviro = Enviro { bombs :: [Bomb], stuff :: [Picture]} When the TimedBomb timer ...
7
votes
1answer
145 views

I'm being warned that the Monoid I'm creating is an Orphan Instance. Is there a better way to write this functionality in?

type PromptSegment = IO (Maybe String) instance Monoid a => Monoid (IO a) where mempty = return mempty mappend = liftA2 (<>) This behaves exactly how I want for my purposes. For ...
2
votes
2answers
127 views

Proper use of typeclasses

I'm trying Haskell's Gloss module, and I found a a pattern of things required to properly display an object: Its position, dimensions, scale and Picture representation. This seemed like a good use ...
3
votes
6answers
939 views

How can IO cause side effects in Functional Programming? [duplicate]

Whenever I read about Haskell, I find that IO can cause side effects. But I do not understand how it would do it? Do we mean that we are writing to a file from one lazy sequence and another lazy ...
2
votes
2answers
185 views

Is it possible to have Ad-Hoc polymorphism with runtime dispatch?

As I did understand, and as it's described here, ad-hoc polymorphism is limited to compile-time dispatch. That is, if we have a function that expects an argument that belongs to a typeclass, we must ...
0
votes
0answers
75 views

Database-like structure in memory

I need a database-like structure that will wrap this: data MsgPackDB = MsgPackDB { dim :: !(V.Vector Int) , rows :: !([DBRow]) } data DBRow = ...
5
votes
2answers
375 views

Alternative to language purity

Purity One of the interesting concepts in Haskell is the purity. However, I am wondering what the pragmatic reasons behind this is - let me explain a bit more before you reject my question. My main ...
12
votes
10answers
2k views

What should I understand before I try to understand functional programming? [closed]

I am pretty well-versed in imperative paradigms. I learned Java and C++ before I dropped out of university, after which I taught myself Python. My problem is that even beginner tutorials get way far ...
1
vote
0answers
79 views

Is there a way to force evaluation in GHCi?

I'm messing around with binary trees, and I'm trying to get a very rough benchmark of a few functions using GHCi. I only want to get the time required to evaluate the test functions; not how long it ...
3
votes
3answers
705 views

Lambda expressions with no parameters in Haskell and / or lambda calculus

In eager languages like Scheme and Python, you can use a lambda expression without parameters to delay evaluation, e.g. in Scheme (Chicken Scheme): #;1> (define (make-thunk x) (lambda () (+ x 1))) ...
0
votes
1answer
107 views

Are there any programming languages that use strict evaluation that also have overloaded values?

Haskell supports overloaded values, where a single overloaded value can behave sort of like a superposition of values each with a different type. For example, here's a simple type class: class Truthy ...
31
votes
5answers
1k views

“A proof is a program; the formula it proves is a type for the program”

This might be a philosophical kind of question, but I believe that there is an objective answer to it. If you read the wikipedia article about Haskell, you can find the following: The language is ...
8
votes
1answer
281 views

Is this a valid design pattern for a Haskell main function?

After developing several Haskell applications I've found myself rigorously segregating impure code and failable (partial) functions from their pure & total counterparts. These efforts have ...
4
votes
1answer
195 views

What does the => symbol do in haskell?

I'm fairly new to learning haskell, so I don't really understand the typing system when it comes to constraints. There's this weird => symbol that doesn't make sense to me. Is it actually just ...
9
votes
2answers
616 views

In-memory datastore in Haskell

I want to implement an in-memory datastore for a web service in Haskell. I want to run transactions in the STM monad. When I google hash table steam Haskell I only get this: Data. BTree. HashTable. ...
5
votes
1answer
418 views

Types in Lisp and Scheme

I see now that Racket has types. At first glance it seems to be almost identical to Haskell typing. But is Lisp's CLOS covering some of the space Haskell types cover? Creating a very strict Haskell ...
1
vote
2answers
217 views

Is there any practical use for the empty type in Common Lisp?

The Common Lisp spec states that nil is the name of the empty type, but I've never found any situation in Common Lisp where I felt like the empty type was useful/necessary. Is it there just for ...
14
votes
5answers
3k views

In what programming language did “let” first appear?

I was wondering about the origins of the "let" used in Lisp, Clojure, and Haskell. Does anyone know which language it appeared in first?
4
votes
2answers
857 views

Type inference in Golang/Haskell

I've read that Go doesn't actually have true type inference in the sense that functional languages such as ML or Haskell have, but I haven't been able to find a simple to understand comparison of the ...
11
votes
5answers
613 views

What is the name of λx.λf.fx (like reverse apply) in lambda calculus? Does the corresponding function have a standard name in programming?

What is the name of λx.λf.fx in lambda calculus? Does the corresponding function have a standard name in functional programming languages, like Haskell? In object oriented programming, is there a ...
15
votes
2answers
345 views

Cleanest way to report errors in Haskell

I'm working on learning Haskell, and I've come across three different ways of dealing with errors in functions I write: I can simply write error "Some error message.", which throws an exception. I ...