A functional programming language

learn more… | top users | synonyms

12
votes
2answers
344 views

Haskell ways to the 3n+1 problem

Here is a simple programming problem from SPOJ: http://www.spoj.com/problems/PROBTRES/. Basically, you are asked to output the biggest Collatz cycle for numbers between i and j. (Collatz cycle of a ...
14
votes
6answers
8k views

Which self balancing binary tree would you recommend?

I'm learning Haskell and as an exercise I'm making binary trees. Having made a regular binary tree, I want to adapt it to be self balancing. So: Which is most efficient? Which is easiest to ...
7
votes
2answers
156 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
61 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 ...
2
votes
1answer
61 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
200 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?
0
votes
0answers
43 views
6
votes
2answers
93 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
53 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
46 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 ...
7
votes
2answers
657 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 ...
2
votes
1answer
129 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
128 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 ...
3
votes
0answers
124 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
174 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 "...
19
votes
1answer
1k 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 ...
5
votes
2answers
160 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 ...
8
votes
2answers
1k views

Implement Haskell typeclass with C# interface

I'm trying to compare Haskell's type classes and C#'s interfaces. Suppose there is a Functor. Haskell: class Functor f where fmap :: (a -> b) -> f a -> f b How to implement this type ...
0
votes
1answer
235 views

Why does this article state that graduate education liberate one from concerns like the efficiency of hardware-based integers? [closed]

Quoting The Evolution of Haskell Programmer, graduate education tends to liberate one from petty concerns about, e.g., the efficiency of hardware-based integers What exactly does this suggest?...
2
votes
1answer
102 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 ...
7
votes
6answers
2k views

A programming language that does not allow IO. Haskell is not a pure language

Are there any 100% pure languages (as I describe in the Stack Overflow post) out there already and if so, could they feasibly be used to actually do stuff? i.e. do they have an implementation? I'm not ...
36
votes
7answers
15k views

Haskell AND Lisp vs. Haskell OR Lisp [closed]

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 ...
65
votes
5answers
9k views

Is Haskell's type system formally equivalent to Java's? [closed]

I realize some things are easier/harder in one language than the other, but I'm only interested in type-related features that are possible in one and impossible/irrelevant in the other. To make it ...
5
votes
3answers
226 views

Should databases be viewed as Monads?

Because any kind of persistence updates/inserts/deletes represents in some sense a kind of state change in a database, it makes me wonder whether databases can be considered monads. We say the same ...
3
votes
1answer
96 views

Can I use maybe on multiple inputs in Haskell?

Suppose I wanted to test that both my inputs are positive. Can I do something like this? test :: Float -> Float -> Maybe Float Float test a b | a>0 && b>0 = a b | ...
24
votes
8answers
4k views

Using a “strong” type system in the real world, say, for large-scale web-apps?

I know this is a very broad, ambiguous, and possibly philosophical question. To an extent, that the most important keyword in the question - "strong" type system - itself, is ill-defined. So, let me ...
3
votes
3answers
118 views

Iterating (mapping) recursive data type in Haskell

This might me a stupid question, but since I don't have anyone to discuss it over a coffee, I think I'd ask it here. So, I'm reading the book "The Haskell School of Expression" to learn myself a bit ...
40
votes
2answers
4k 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 ...
4
votes
3answers
221 views

How to use a strong type system to model business constraints?

Following up on my ambiguous question, here's a question that is probably more focused. Consider the following code snippet form a Haskell program: data NightWatchCommand = InvalidCommand | ...
18
votes
2answers
891 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 ...
5
votes
6answers
2k 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 ...
4
votes
2answers
526 views

Why do textbooks use pseudocode rather than real languages?

In colleges and in algorithm textbooks, it is quite common for the teacher and author to explain control flow in pseudo-code. With the advent of more expressive languages like Python and Haskell among ...
8
votes
1answer
233 views

Computer Architectures NOT based on arrays [closed]

Wadler's original paper on Monads for Functional Programming ( Haskell ) ,he says Another question with a long history is whether it is desirable to base programs on array update. Since so much ...
4
votes
3answers
3k 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))) ...
2
votes
2answers
156 views

What is the equivalent of The Little Lisper project in Haskell?

In the book The Little Lisper, you implement a minimal Scheme in 10 Chapters that is capable of interpreting any chapter in the book. To me it seems you could do the same for a 'minimal subset of a ...
1
vote
0answers
64 views

Chronological/evolutionary positioning of Curry in relation to Haskell and Prolog

is Curry a transitional language from FP to Logic Programming (Haskell to Prolog), like Scala is a transitional language from imperative to FP (Java to Haskell)? I find it hard to come up with a ...
23
votes
4answers
3k views

Is return-type-(only)-polymorphism in Haskell a good thing?

One thing that I've never quite come to terms with in Haskell is how you can have polymorphic constants and functions whose return type cannot be determined by their input type, like class Foo a ...
1
vote
2answers
214 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, ...
2
votes
2answers
198 views

Haskell types for functions

I don't understand the answer to this question: Q: Can Haskell find a type for the function selfapply defined by: selfapply f = f f A: The function selfapply is not typeable in the simple ...
8
votes
4answers
359 views

Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?

In Haskell, I can use the type a -> Maybe b to model a function that either returns a value of type b, or returns nothing (it fails). If I have types a1, ..., a(n+1) and functions f1, ..., fn, ...
7
votes
6answers
1k views

Does it make sense to use the term “Space Leak” with regard to Java?

EDIT: To clarify, I am not suggesting that leaks don't happen in a managed application. I'm simply pondering about how we talk about them. There are some highly upvoted discussions about memory ...
35
votes
5answers
2k 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 ...
5
votes
4answers
637 views

How does “repeat x = x:repeat x” return a list in Haskell?

This is supposed to return an infinite list of x's. However a list is created using an element, then the operator ':' and then a list. The recursive definition of repeat' x = x:repeat' x seems to ...
3
votes
2answers
177 views

Haskell: Is it possible to convert a Num to a Float?

I need to be able to convert generic numbers (instances of Num) to a Float. I searched Hoogle for a function with the signature Num n => n -> Float, but I couldn't find any such functions (...
6
votes
3answers
208 views

What is the purpose of wrapped values in Haskell?

I've recently read an article about Functors, Applicatives and Monads in Haskell and it concludes with these statements: functors: you apply a function to a wrapped value using fmap or <$> ...
133
votes
5answers
27k views

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

I'm starting to learn Haskell. I'm very new to it, and I 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 ...
67
votes
2answers
11k views

What is the “Free Monad + Interpreter” pattern?

I've seen people talking about Free Monad with Interpreter, particularly in the context of data-access. What is this pattern? When might I want to use it? How does it work, and how would I implement ...
42
votes
7answers
7k views

How do you encode Algebraic Data Types in a C#- or Java-like language?

There are some problems which are easily solved by Algebraic Data Types, for example a List type can be very succinctly expressed as: data ConsList a = Empty | ConsCell a (ConsList a) consmap f ...
4
votes
2answers
370 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 ...
5
votes
3answers
2k views

What is this algorithm for converting strings into numbers called?

I've been doing some work in Parsec recently, and for my toy language I wanted multi-based fractional numbers to be expressible. After digging around in Parsec's source a bit, I found their ...