![]() |
Haskell
Does anyone have any experience with Haskell?
I've been trying to learn the language (based on the principle that if you can learn Haskell, you can learn anything), and I've been writing a number of small programs to help me learn. One of the programs is a module that implements a bag data structure (similar to a set, but keeps track of the amounts of each item). I've been trying to construct a function to give me a sub-bag of the N most common elements, but I have yet to have much luck. Here's what I have so far: :
module Bag where |
For those interested, here's a working (if limited) bag module:
:
module Bag where |
Clean (http://www.cs.ru.nl/%7Eclean/index.html) is also an interesting language to check out, I was learning this for a while, it's based on Haskell for the most part but adds other functional programming concepts including some features not found in other languages.
|
Arevos, I've been bored lately so I took up your challenge. This is the beginnings of a card module I wrote after reading for about 3-4 hours. At this point, I don't really understand monads, but I think I'm doing the random stuff correctly.
Cards.hs :
-- Written by Jessehk onMain.hs :
module Main |
Quote:
Quote:
I found monads are tricky not because they're inherently complex, but because they're such a generic concept it's difficult to relate them back to practical problems. The You-Could-Have article neatly bridges that gap, I discovered. |
Thanks for the article, I'll have a look. :)
Haskell is interesting, but any idea that somebody with not a lot of programming experience could learn on Haskell is just wrong (IMO). For a start, the standard library documentation is very unforgiving (very little hand-holding). |
You may be correct; I'm certainly having to do some mental adjustment. In the absence of documentation, you're certainly right.
On the other hand, learning to solve problems without the overhead of preconceptions coming from non-functional languages may make learning from scratch no more difficult than learning to solve problems using other languages. Low level procedural languages are certainly not a good match for our natural, more abstract mental processes. |
Quote:
For instance, previously, I wrote a mostCommon function using standard functional techniques, such as fold and filter. However, now I can't help wondering if I couldn't create a simpler, more abstract function by making use of all the functions in Haskell that operate upon monads. I'll try and see if it's possible to come up with something better. I think the attraction of Haskell is not so much that it is functional, but because it enables developers to play around with very abstract concepts in a way other languages can't easily match. It's my opinion that a lot of what makes a good programmer good is his or her ability to think abstractly about a problem. For instance, a beginner who wanted to calculate the first 10 fibonacci numbers might do something like this: :
def fib(n)::
def fib(n)::
fib = 1 : 1 : zipWith (+) fib (tail fib) |
To me, the recursion seems somewhat natural. The idea that you can apply a function to something that reapplies it after making a step variation by some means seems neat. I'm still very raw with it, but I'm thinking of applying it to the tic tac toe game, as a learning exercise. Because the number of possible moves (especially when reduced by the idea of equivalence) is not terribly large, the lazy sequence wouldn't be infinite, but would terminate after nine moves or when a win or draw was detected. No pruning, ala chess, should be necessary -- the end should be reachable without resorting to pruning. This means that the outcome is a distinct value, and not a guess or approximation based on some set of evaluation rules. This thing of highly modular functions that can be composed into more complex functions, applicable to varying types, is just intriguing to me. I haven't messed with Lisp since the early 90s, but the notion of the Haskell list is distinctly familiar.
|
Quote:
|
| All times are GMT -5. The time now is 12:17 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC