A functional programming language

learn more… | top users | synonyms

0
votes
1answer
79 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 ...
1
vote
0answers
124 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. ...
11
votes
1answer
321 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
121 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 ...
3
votes
1answer
84 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
118 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
102 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 ...
0
votes
2answers
130 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
101 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
742 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
71 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 = ...
4
votes
2answers
223 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
64 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
184 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
95 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 ...
8
votes
1answer
257 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
158 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
207 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
358 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 ...
9
votes
2answers
194 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
178 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
594 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
112 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
94 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
90 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
157 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
187 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 ...
24
votes
2answers
2k 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
187 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
167 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
92 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
353 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
220 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
299 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
243 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
117 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 ...
1
vote
3answers
139 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
492 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 ...
44
votes
2answers
5k 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
314 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
229 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
132 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
193 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
198 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
219 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
2k 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
140 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
728 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
295 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. ...