In this declaration
data Const a = Const Integer
Haskell infers that Const is * -> *. Is it possible to make Const take a type constructor instead, so it will be (* -> *) -> *? Ideally, it should be a -> *, but there are no polymorphic kinds. This thread shows one solution - adding unused constructor. Has the situation changed since 2...
I'm doing a complicated hack in Python, it's a problem when you mix for+lambda+*args (don't do this at home kids), the boring details can be omited, the unique solution I found to resolve the problem is to pass the lambda object into the self lambda in this way:
for ...
lambda x=x, *y: foo(x, y, <selflambda>)
It's possible?, thank...
More specifically, how do I generate a new list of every Nth element from an existing infinite list?
E.g. if the list is [5, 3, 0, 1, 8, 0, 3, 4, 0, 93, 211, 0 ...] then getting every 3rd element would result in this list [0,0,0,0,0 ...]
...
I've come across the term 'Functor' a few times while reading various articles on functional programming, but the authors typically assume the reader already understands the term. Looking around on the web has provided either excessively technical descriptions (see the Wikipedia article) or incredibly vague descriptions (see the section ...
I am trying to learn F# so I paid a visit to Project Euler and I am currently working on problem 3.
The prime factors of 13195 are 5, 7,
13 and 29.
What is the largest prime
factor of the number 600851475143?
Some things to consider:
My first priority is to learn good functional habits.
My second priority is I would like...
I want to give a Scala presentation and I want to do it by taking an application and evolve it from something which uses java idioms to something that uses the power of scala (traits, pattern matching, implicit convertions, functional programming).
I'm especially interested in something that demonstrates a design change, rather than sy...
I have just solved problem23 in Project Euler, in which I need a set to store all abundant numbers. F# has a immutable set, I can use Set.empty.Add(i) to create a new set containing number i. But I don't know how to use immutable set to do more complicated things.
For example, in the following code, I need to see if a number 'x' could ...
Seq.max finds the max number. I'd like to have something like Seq.findIndex
Seq.maxIndex returns the index of the maximum element.
...
The following two Haskell programs for computing the n'th term of the Fibonacci sequence have greatly different performance characteristics:
fib1 n =
case n of
0 -> 1
1 -> 1
x -> (fib1 (x-1)) + (fib1 (x-2))
fib2 n = fibArr !! n where
fibArr = 1:1:[a + b | (a, b) <- zip fibArr (tail fibArr)]
They are very close to math...
For some reason, I tend to associate closures with functional languages. I believe this is mostly because the discussions I've seen concerning closures is almost always in an environment that is focused around functional programming. That being said, the actual practical uses of closures that I can think are are all non-functional in nat...
I'm an Object Oriented programmer looking forward to learning a functional language. My questions are:
When do you choose functional programming over object oriented ?
What are the typical problem definitions where functional programming is a better choice?
...
Hi everyone,
I am a beginner to functional programming and I have recently started studying Scala and I really love this language for the all goodies it provides like closures, pattern matching, currying etc.
However I am not able to understand the point of Option[T] class in Scala. I mean, I am not able to see any advanages of None ov...
Possible Duplicates:
What’s a good book for learning F#?
Good F# Programming Books
With the upcomming release of Visual Studio 2010, I want to broaden my knowledge of F# and functional programming in general.
Which particular book(s) can you recommend and why?
...
I've been looking at Haskell lately and it seems like a very nice way to watch programming problems from an alternative point of view - alternative to my usual imperative (I have a strong C++ background) view, at least.
However, all the articles I see seem to deal with the same kinds of programming problems:
Parsers
Compilers
Numeric ...
Lately I've been thinking a lot about functional programming. Perl offers quite a few tools to go that way, however there's something I haven't been able to find yet.
Prototype has the function detect for enumerators, the descriptions is simply this:
Enumerator.detect(iterator[, context]) -> firstElement | undefined
Finds the first ele...
In CSS2 and even in the upcoming CSS3, I can't find something that would be completely natural and time-saving - applying CSS styles from within other styles, rather than from HTML.
For example:
.awesome-image {
border: 1px #000 solid;
margin: 2px;
}
.super-awesome-image {
.alwesome-image; // or something like that - this is sim...
I've seen some elegant python snippets using list comprehension and map reduce. Can you share some of these code or a web site.
Thanks.
...
resistors.org site and foxthompson.net download links are stale/broken.
http://www.resistors.org/index.php/The_SAM76_programming_language
Every other link I've been able to track down on the 'net (mostly in old newsgroup posts) are broken. E-mails to the respective webmasters all bounced.
I have a morbid curiosity for arcane programm...
I need small lists of gaussian random numbers for a simulation and so I tried the following:
import System.Random
seed = 10101
gen = mkStdGen seed
boxMuller mu sigma (r1,r2) = mu + sigma * sqrt (-2 * log r1) * cos (2 * pi * r2)
This is just the Box-Muller algorithm - given r1, r2 uniform random numbers in the [0,1] interval it ret...
I'm using Firefox 3.5.7 and within Firebug I'm trying to test the array.reduceRight function, it works for simple arrays but when I try something like that I get a NaN. Why?
>>> var details = [{score : 1}, {score: 2}, {score: 3}];
>>> details
[Object score=1, Object score=2, Object score=3]
>>> details.reduceRight(function(x, y) {return...