A functional programming language

learn more… | top users | synonyms

3
votes
1answer
127 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 ...
1
vote
0answers
159 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 ...
2
votes
2answers
108 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 ...
7
votes
2answers
146 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 ...
5
votes
1answer
166 views

How should I recursively process a file in Haskell?

Basically I'm expanding a literate program in Haskell. There are two things I need to look for to expand. Here's an example file: program.c.lit: ============== Some comments in the source file that I ...
3
votes
2answers
407 views

Haskell syntax for type definitions: why the equality sign?

I am a bit confused by the choice of Haskell syntax for type definitions, like in data Foo = Bar Namely: does the equality sign here really mean an equality in some subtle sense, or is it just a ...
4
votes
2answers
83 views

How do you handle specific networking exceptions in Haskell?

I have the following to try and connect to a server: testAddress :: HostName -> Int -> IO (Maybe Handle) testAddress host iPort = do let port = PortNumber $ fromIntegral iPort putStrLn ...
1
vote
1answer
86 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 ...
2
votes
0answers
76 views

Why do Haskell functors only have derived types in their target category?

In Haskell, the Functor typeclass functor is defined as follows (see e.g. Haskell wiki): class Functor (f :: * -> *) where fmap :: (a -> b) -> f a -> f b As far as I understand ...
2
votes
1answer
88 views

Difference between Yesod and Ocsigen web frameworks [closed]

I have been looking at web-frameworks in functional languages and eventually found Yesod and Ocsigen interesting. As far as I understand, they leverage the type system to statically prevent basic ...
1
vote
2answers
175 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 ...
22
votes
2answers
1k views

Do modern languages still use parser generators?

I was researching about the gcc compiler suite on wikipedia here, when this came up: GCC started out using LALR parsers generated with Bison, but gradually switched to hand-written ...
5
votes
2answers
138 views

Is it safe in Haskell to save a data structure to a file using “show”, and retrieve it using “read”?

Say I have the following types: type EndsTup = (Int,Int) -- (0-based index from start or end, Frequency) type FreqTup = (Char, [EndsTup], [EndsTup]) -- (Character, Freqs from start, Freqs ...
3
votes
2answers
131 views

How can a true Vector be implemented in Haskell?

How could a true Vector type be implemented in Haskell? In order for something to be a Vector, it has to be stored sequentially in memory, with O(1) random access. But Haskell hides its memory ...
1
vote
4answers
85 views

What's the proper way of dealing with a global file path?

I don't have compilable code, because the code in question depends on a large function that's irrelevant to the question, but say I have the following scenario: savePath = "C:\\..." changePath1, ...
1
vote
2answers
287 views

How bad is using underscore in names? [closed]

I am mainly a C programmer. In my world, writing likeThis or like_this is just a matter of style. In Haskell however, it seems that camelCase is the definite choice. Personally, I find the later much ...
4
votes
1answer
196 views

Why does Haskell's built in max function run faster than mine?

I noticed that for some reason, Haskell's built in max function (which returns the greatest of two numbers) runs much faster than the one I wrote, even though they are essentially identical. From ...
5
votes
1answer
287 views

Who invented Haskell's type classes?

Haskell's type classes are a very powerful tool and give Haskell a great expressive ability, compared to functional languages that don't have them. When were they invented, and who invented them?
1
vote
2answers
200 views

Is Haskell appropriate for Signal Processing, Communication Systems and Information Theory? [closed]

I have been working on Software-Defined Radio projects for almost a year. This is an area which requires lots of signal processing (digital filters and FFTs), communication theory (modulation, ...
3
votes
1answer
106 views

Why are data constructors with the same name disallowed in different type constructors?

The following declaration gives an error: type Vec2d = (Float, Float) type Vec3d = (Float, Float, Float) -- Rect x y defines a rectangle spanning from (0,0) to (x,y) data Obj2d = Rect Float Float ...
0
votes
3answers
121 views

Are functional languages a kind of program derivation?

Program derivation is defined as the derivation of a program from it's specifications. Usually this specification language is some form of propositional logic, but from what I understand, it need not ...
5
votes
1answer
408 views

Is there an imperative language with a Haskell-like type system? [closed]

I've tried to learn Haskell a few times over the last few years, and, maybe because I know mainly scripting languages, the functional-ness of it has always bothered me (monads seem like a huge mess ...
40
votes
2answers
4k 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 ...
7
votes
1answer
304 views

Relation between objects

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

Why isn't Haskell able to optimize infinite lists?

Lets say you've got a list l = [0, 2..] and you want to get the nth number when n is pretty large, say n=123456789. So you call l !! 123456789. On my machine, this results in out of memory. So why ...
6
votes
2answers
147 views

Guidelines for returning collections from public functions

The Problem Imagine you have a function in a public API that needs to return some kind of collection. Its type is something like foo :: a -> b where b is some kind of collection. As far as I ...
2
votes
1answer
123 views

To which level Haskell's HDBC is lazy?

The HDBC documentation states: fetchAllRows :: Statement -> IO [[SqlValue]]Source Lazily fetch all rows from an executed Statement. You can think of this as hGetContents applied to a ...
2
votes
1answer
160 views

Picking a card from a shuffled deck

I'm pretty new to Haskell although I did some ML many moons ago. I'm trying to set up a deck of playing cards, shuffle them and then deal them. I have the deck and shuffle sorted (of a fashion) but ...
1
vote
1answer
187 views

What is this programming style? “Monoid-ic”?

In a moderately old blog post, Conal Elliot makes an interesting (if less than serious) argument that C is a purely functional language, by drawing a parallel between the combination of the C ...
1
vote
2answers
179 views

Why does a monad use “return” or “unit” rather than “lift”?

This is partly genuine curiosity, and partly a check on my understanding. I'm probably missing the point. In Haskell, why does a monad use operations called return or unit to describe putting a type ...
15
votes
4answers
1k views

How does persistence fit into a purely functional language?

How does the pattern of using command handlers to deal with persistence fit into a purely functional language, where we want to make IO-related code as thin as possible? When implementing ...
1
vote
2answers
106 views

Mapping a list of optional values to an optional list of values

I have encountered the following pattern while programming in Haskell (but the pattern could occur in any language supporting lists, option types, and mapping of a function over a list). I have types ...
5
votes
4answers
594 views

Why doesn't Haskell have a 'format' function for string interpolation?

I'm trying to use Shake and I stumbled upon the following problem: there's no easy and convenient way to interpolate a string. I know about Text.Printf — it's not what I'm looking for. The ...
4
votes
2answers
276 views

Better way to familiarize myself with Haskell [closed]

I'm a Haskell beginner. I started learning Haskell around 20-25 days back. With a programming day job I am doing this in my spare time because I wanted to learn about functional programming. ...
3
votes
2answers
378 views

Is there any particular reason for the use of lists over queues in functional programming languages?

Most functional programming languages such as Scheme and Haskell use lists as their main data structure. Queues are identical to lists, except for the fact appending to the end - not to the begin - ...
1
vote
1answer
139 views

Building proprietary software over haskell compiler [closed]

Is it perfectly legal to use GHC as base and build some commercial application over its top ? Are there such examples I can can interact with ?
5
votes
2answers
258 views

Can someone explain the concept behind Haskell's memoization?

(note I'm putting the question here because it's about the conceptual mechanics of it, rather than a coding problem) I was working on a small program, that was using a sequence of fibonacci numbers ...
10
votes
2answers
404 views

Are types erased in Haskell?

Haskell has a notion of “generic functions” that has some apparent similarity with common lisp—having neither experience with Haskell nor with common lisp, I might be very approximative here. This ...
5
votes
2answers
533 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 ...
15
votes
2answers
400 views

Side effect-free interface on top of a stateful library

In an interview with John Hughes where he talks about Erlang and Haskell, he has the following to say about using stateful libraries in Erlang: If I want to use a stateful library, I usually build ...
0
votes
1answer
184 views

Haskell: Best tools to validate textual input?

In Haskell, there are a few different options to "parsing text". I know of Alex & Happy, Parsec and Attoparsec. Probably some others. I'd like to put together a library where the user can input ...
18
votes
2answers
947 views

Type checking and recursive types (Writing the Y combinator in Haskell/Ocaml)

When explaining the Y combinator in the context of Haskell, it's usually noted that the straight-forward implementation won't type-check in Haskell because of its recursive type. For example, from ...
9
votes
1answer
443 views

Why isn't there a typeclass for functions?

In a learning problem I've been messing around with, I realised I needed a typeclass for functions with operations for applying, composing etc. Reasons... It can be convenient to treat a ...
4
votes
3answers
2k 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 ...
8
votes
2answers
615 views

Can *any* program task be expressed without state?

This is a theoretical question, but after many years of programming in what I now realize is "normal" imperative technique, using C++ mainly, I've discovered this other world of functional ...
11
votes
2answers
671 views

Functional programming and stateful algorithms

I'm learning functional programming with Haskell. In the meantime I'm studying Automata theory and as the two seem to fit well together I'm writing a small library to play with automata. Here's the ...
5
votes
1answer
572 views

Maths needed to understand theory behind Haskell's type system?

Recently, I've become deeply interested in Haskell. While attempting to learn new concepts (e.g. the forall keyword and ST monad) and Haskell's type system in general, I continually run into ...
5
votes
1answer
279 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, ...
16
votes
3answers
5k views

What are the advantages of using LISP and Haskell? Will they make me a better programmer? [closed]

I know Lisp and Haskell are functional and logic programming languages respectively, but what exactly does this mean? How do they differ from other languages? I've heard that learning these will make ...
0
votes
2answers
689 views

Why don't we have a non-turing complete general purpose language yet? [duplicate]

Non-turing complete languages can solve every practical problem that a turing-complete language can. Also, they are much more analyzable than turing complete languages. The compiler can comprehend the ...