functional-programming

State Monad, why not a tuple?

青春壹個敷衍的年華 提交于 2019-12-18 15:35:55
问题 I've just wrapped my head around monads (at least I'd like to think I have) and more specifically the state monad, which some people that are way smarter then me figured out, so I'm probably way of with this question. Anyway, the state monad is usually implemented with a M<'a> as something like this (F#): type State<'a, 'state> = State of ('state -> 'a * 'state) Now my question: Is there any reason why you couldn't use a tuple here? Other then the possible ambiguity between MonadA<'a, 'b> and

In Haskell, what's the difference between using takeWhile or using a “regular” inequality in this list comprehension?

痞子三分冷 提交于 2019-12-18 14:51:51
问题 I'm trying to learn me a Haskell (for great good), and one of the many different things I'm doing is trying to tackle some Project Euler problems as I'm going along to test my mettle. In doing some of the Fibonacci based problems, I stumbled on and started playing around with the recursive infinite list version of the Fibonacci sequence: fibs = 1 : 2 : zipWith (+) fibs (tail fibs) For one of the PE problems, I needed to extract the subsequence of even Fibonacci numbers less than 4,000,000. I

In Haskell, what's the difference between using takeWhile or using a “regular” inequality in this list comprehension?

一曲冷凌霜 提交于 2019-12-18 14:51:51
问题 I'm trying to learn me a Haskell (for great good), and one of the many different things I'm doing is trying to tackle some Project Euler problems as I'm going along to test my mettle. In doing some of the Fibonacci based problems, I stumbled on and started playing around with the recursive infinite list version of the Fibonacci sequence: fibs = 1 : 2 : zipWith (+) fibs (tail fibs) For one of the PE problems, I needed to extract the subsequence of even Fibonacci numbers less than 4,000,000. I

state of web development using functional programming language

限于喜欢 提交于 2019-12-18 12:59:05
问题 I am considering ditching Ruby on Rails for my web-development pet-project and using a functional programming language (with or without a framework). Not that there is anything wrong with RoR, but I'd just like to learn something else and it seems a good way to learn functional programming. I know of a couple frameworks (Lift for Scala and Seaside for Smalltalk) and I know there are also web-related Haskell libraries available. Finally I imagine that everything could be written from scratch.

Scala case class prohibits call-by-name parameters?

青春壹個敷衍的年華 提交于 2019-12-18 12:47:38
问题 Scenario: I want to implement an infinite list: abstract class MyList[+T] case object MyNil extends MyList[Nothing] case class MyNode[T](h:T,t: => MyList[T]) extends MyList[T] //error: `val' parameters may not be call-by-name Problem: The error is that call-by-name is not allowed. I've heard that it is because val or var constructor parameter is not allowed for call-by-name . For example: class A(val x: =>Int) //error: `val' parameters may not be call-by-name But in contrast the normal

How does one implement hash tables in a functional language?

有些话、适合烂在心里 提交于 2019-12-18 12:47:30
问题 Is there any way to implement hash tables efficiently in a purely functional language? It seems like any change to the hash table would require creating a copy of the original hash table. I must be missing something. Hash tables are pretty darn important data structures, and a programming language would be limited without them. 回答1: Is there any way to implement hash tables efficiently in a purely functional language? Hash tables are a concrete implementation of the abstract "dictionary" or

What is the lifetime of a memoized value in a functional language like Haskell?

南笙酒味 提交于 2019-12-18 12:15:45
问题 In a pure functional language with lazy semantics (such as Haskell), results of computations are memoized so that further evaluations of a function with the same inputs do not recompute the value but get it directly from the cache of memoized values. I am wondering if these memoized values get recycled at some point in time? If so, it means that the memoized values must be recomputed at a later time, and the benefits of memoization are not so exiting IMHO. If not, then ok, this is clever to

Which language in DrScheme for SICP?

江枫思渺然 提交于 2019-12-18 11:51:52
问题 I have been using the Module for SICP in DrScheme 4.2 but which language has the best support for SICP in DrScheme? Has anyone here tried this? Thanks. 回答1: I don't think you need anything but R5RS which is available in DrScheme via Language > Choose Language... . You might want to allow redefinition of bindings. After you have selected R5RS, click on " Show Details " and uncheck " Disallow redefinition of initial bindings ". Some places in the text uses an error function, which is not

alternative to typeclasses?

一世执手 提交于 2019-12-18 11:40:27
问题 haskell programmer. using F#. no typeclasses in F#. what to use when I need typeclasses? 回答1: Do check out this as someone suggested. I think the short answer is to pass dictionaries-of-operations (as Haskell would under the hood; the witness for the instance). Or change the design so you don't need typeclasses. (This always feels painful, since typeclasses are the best thing ever and it's hard to leave them behind, but before Haskell and typeclasses came along, people still managed to

References for learning the theory behind pure functional languages such as Haskell?

别等时光非礼了梦想. 提交于 2019-12-18 11:37:15
问题 While learning Haskell I had the feeling that the authors where not always telling me everything, so to truly understand it I would like to know the theory behind the type system, monads and concepts like that. Most of these concepts come from Category Theory I heard, so what are some good books/websites on this topic and related topics? 回答1: Papers by Philip Wadler and Simon Peyton Jones should get you started on the theory behind Haskell. The book The Implementation of Functional