A functional programming language

learn more… | top users | synonyms

0
votes
2answers
105 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: ...
2
votes
2answers
76 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 ...
3
votes
6answers
690 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 ...
0
votes
0answers
61 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 = ...
3
votes
2answers
177 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 ...
0
votes
0answers
58 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 ...
2
votes
3answers
90 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
85 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 ...
7
votes
1answer
235 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 ...
3
votes
1answer
148 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
176 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
185 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 ...
8
votes
2answers
160 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 ...
4
votes
1answer
169 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
426 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
94 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
89 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
84 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
118 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
177 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 ...
23
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
147 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
138 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
87 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
308 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
204 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
292 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
222 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
111 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
127 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
458 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 ...
42
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
310 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 ...
2
votes
2answers
216 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
149 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
127 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 ...
1
vote
1answer
172 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
189 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
185 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
109 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
645 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
285 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. ...
4
votes
2answers
385 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
144 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
296 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
414 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
566 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
404 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
198 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 ...