A functional programming language
2
votes
3answers
87 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 ...
4
votes
2answers
457 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 ...
6
votes
1answer
211 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 ...
10
votes
2answers
254 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 ...
4
votes
3answers
174 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 | ...
2
votes
2answers
137 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
55 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 ...
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 ...
22
votes
8answers
3k 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 ...
5
votes
4answers
603 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 ...
6
votes
3answers
183 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 <$>
...
3
votes
2answers
162 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 ...
4
votes
1answer
73 views
Performance of list concatenation followed by scanning
Consider the following code snippet:
-- list_1 = [1, 2, 3]
-- list_2 = [4, 5, 6]
final_list = list_1 ++ list_2
result = map (+1) final_list
Is the time spent by it proportional just to the length ...
6
votes
3answers
179 views
Why don't “multi-infinite” list comprehensions work with lazy evaluation?
As a simple demonstration of the efficiency of Haskell style, I thoughtlessly ran the following:
take 100 [(a, b, c) | a <- [1..], b <- [1..], c <- [1..], a^2 + b^2 == c^2]
This should be a ...
0
votes
1answer
99 views
The use of '#'-sign in haskell program text
What do those #-signs mean? For example,
data Word = W# Word# deriving (Eq, Ord)
I tried to google it but I found nothing.
8
votes
4answers
346 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, ...
0
votes
0answers
89 views
Haskell + OpenGL framework
I'm writing a framework in Haskell where I'd like to use OpenGL to draw lines, shapes... I'm encountering a problem defining the structure of my program. I have for example a Polyline type which holds ...
1
vote
1answer
82 views
how do interpreters differ for statically- or dynamically-typed languages?
Writing an interpreter for a dynamically typed language usually involves creating an Environment, a data structure which stores mappings of variable names to their values. Values are boxed in some ...
3
votes
1answer
212 views
How to manage the state in a GUI app with Haskell
I am using wxHaskell to create a simple GUI that has typical components like Buttons, Panels, etc.
When some of these components perform an action (like callback), the generic status of the ...
4
votes
2answers
140 views
Functional Programming - Functions defining specific evaluation of functions passed to it for optimization
Firstmost, I am just getting started with functional programming so I would appreciate corrections in any terminology I may have used incorrectly.
Story time, While doing a Project Euler Problem 1 in ...
13
votes
1answer
236 views
Why is Haskell unable to avoid repeated evaluation without the monomorphism restriction?
I just finished learnyouahaskell the other day, and I was trying to make sense of the Monomorphism Restriction, as described by the Haskell Wiki. I think I understand how the MR can prevent repeated ...
2
votes
2answers
178 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 ...
3
votes
2answers
278 views
Why are the types in Java considered less 'strong' than haskell?
I asked this question a while ago - the answers were really helpful, and as I read them and the questions that were linked - I also saw this, and the first answer I think really addresses what I ...
9
votes
2answers
511 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 ...
121
votes
5answers
24k 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 ...
18
votes
2answers
851 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 ...
8
votes
2answers
262 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 ...
16
votes
1answer
461 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
2answers
193 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, ...
1
vote
1answer
126 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 ...
-3
votes
2answers
281 views
haskell - are tuples defined recursively? [closed]
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?
5
votes
0answers
150 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
216 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 ...
6
votes
1answer
190 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 ...
3
votes
2answers
239 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 ...
0
votes
2answers
204 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 ...
14
votes
2answers
1k 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
293 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
100 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
184 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
150 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
4answers
220 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
379 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
1k 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 ...
5
votes
2answers
753 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 ...
1
vote
0answers
126 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 ...
4
votes
3answers
2k 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
143 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
357 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
267 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 ...