On Oct 31, 2005, at 6:06 PM, Matt Mower wrote:
Hi there,
Anyone working on a bundle for Haskell?
M
-- Matt Mower :: http://matt.blogs.it/
Indeed, Jamis Buck just blogged about starting one!
http://jamis.jamisbuck.org/articles/2005/11/01/haskell-bundle-for- textmate
Hi Scott,
On 01/11/05, Scott Barron scott@elitists.net wrote:
On Oct 31, 2005, at 6:06 PM, Matt Mower wrote:
Anyone working on a bundle for Haskell?
Indeed, Jamis Buck just blogged about starting one!
That's great, many thanks for the link. It may actually have been one of Jamis' posts that got me to take a (first) look at Haskell last night.
So far I can't actually get any code to run in the GHC interpreter, something about my functions not being in scope... a most confusing start, worse even than Lisp :-)
Regards,
Matt
-- Matt Mower :: http://matt.blogs.it/
On Tue, 1 Nov 2005, Matt Mower wrote:
So far I can't actually get any code to run in the GHC interpreter, something about my functions not being in scope... a most confusing start, worse even than Lisp :-)
Yeah... one of the great problems with Haskell is the relative paucity of "Haskell for n00bs" type documentation. A couple of good sources are Two Dozen Short Lessons in Haskell [1], and Yet Another Haskell Tutorial [2] (note that Two Dozen uses hugs, not ghci).
[1] http://www.cs.ou.edu/cs1323h/textbook/haskell.shtml [2] http://www.isi.edu/~hdaume/htut/
Your problem seems to be that either you haven't loaded the module(s) containing your functions, or you've loaded multiple modules and, in the process, hid the modules with the functions you wanted. There are a couple of ways to fix this. Say you have the following two files:
------ Pa.hs: module Pa where
parallel_apply [] _ _ = [] parallel_apply (f:fs) xs ys = (zipWith f xs ys):(parallel_apply fs xs ys)
Ftest.hs: module Ftest where
fact 0 = 1 fact x = x * fact (pred x) -----
Now, how can you use the functions fact and parallel_apply in ghci? Well, one way is to pass them to ghci on the command line (note, we will be assuming that we launch ghci from the directory containing Pa.hs and Ftest.hs):
[228] 12:51PM% ghci Pa ftest
This tells ghci to load our code and make it available. We are (eventually) met with the message and prompt: Loading package base-1.0 ... linking ... done. Compiling Pa ( Pa.hs, interpreted ) Compiling Ftest ( ftest.hs, interpreted ) Ok, modules loaded: Ftest, Pa. *Ftest>
This tells us that the modules Pa and Ftest were loaded, and the prompt tells us that the module Ftest is at the top level, i.e. all of its defenitions are in scope. Let's try it out:
*Ftest> fact 10 3628800
So far so good. Now let's try parallel_apply:
*Ftest> parallel_apply [(+), (*)] [1,2,3] [4,5,6]
<interactive>:1:0: Not in scope: `parallel_apply'
Nuts... we can't get at it, because Ftest is hiding it. We can, however, reach it by its qualified name:
*Ftest> Pa.parallel_apply [(+), (*)] [1,2,3] [4,5,6] [[5,7,9],[4,10,18]]
Note that if the prompt read *Pa>, then the definitions from module Pa woult be at the toplevel, and to access fact, we'd need to say, e.g. Ftest.fact 10.
Now, you can get the same effect if you launch ghci without specifying any modules at the command line by using the :load and :add commands
Prelude> :load Pa Compiling Pa ( Pa.hs, interpreted ) Ok, modules loaded: Pa. *Pa> :add Ftest Compiling Ftest ( Ftest.hs, interpreted ) Ok, modules loaded: Ftest, Pa. *Ftest> fact 10 3628800 *Ftest> parallel_apply [(+), (*)] [1,2,3] [4,5,6]
<interactive>:1:0: Not in scope: `parallel_apply' *Ftest> Pa.parallel_apply [(+), (*)] [1,2,3] [4,5,6] [[5,7,9],[4,10,18]]
Here, the last loaded module is the visible one. You can also load modules together:
Prelude> :load Pa Ftest Compiling Pa ( Pa.hs, interpreted ) Compiling Ftest ( Ftest.hs, interpreted ) Ok, modules loaded: Ftest, Pa. *Ftest> fact 10 3628800 *Ftest> Pa.parallel_apply [(+), (*)] [1,2,3] [4,5,6] [[5,7,9],[4,10,18]]
And if you want to have them both at the top level, you can create a third file and make use of the import keyword: ----- Pf.hs: module Pf where
import Ftest import Pa -----
Now you can fire up ghci and load the Pf module: Prelude> :load Pf Compiling Ftest ( ./Ftest.hs, interpreted ) Compiling Pa ( ./Pa.hs, interpreted ) Compiling Pf ( Pf.hs, interpreted ) Ok, modules loaded: Pf, Pa, Ftest. *Pf> fact 10 3628800 *Pf> parallel_apply [(+), (*)] [1,2,3] [4,5,6] [[5,7,9],[4,10,18]]
Or you can use import qualified which requires that you prefix names with the name of its original module: ----- Pf.hs: module Pf where
import qualified Ftest import qualified Pa -----
Prelude> :load Pf Compiling Ftest ( ./Ftest.hs, interpreted ) Compiling Pa ( ./Pa.hs, interpreted ) Compiling Pf ( Pf.hs, interpreted ) Ok, modules loaded: Pf, Pa, Ftest. *Pf> fact 10
<interactive>:1:0: Not in scope: `fact' *Pf> parallel_apply [(+), (*)] [1,2,3] [4,5,6]
<interactive>:1:0: Not in scope: `parallel_apply' *Pf> Ftest.fact 10 3628800 *Pf> Pa.parallel_apply [(+), (*)] [1,2,3] [4,5,6] [[5,7,9],[4,10,18]]
Anyway, sorry for going so far off the TextMate topic...
William D. Neumann
---
"There's just so many extra children, we could just feed the children to these tigers. We don't need them, we're not doing anything with them.
Tigers are noble and sleek; children are loud and messy."
-- Neko Case
Life is unfair. Kill yourself or get over it. -- Black Box Recorder
Hi guys,
On 01/11/05, William D. Neumann wneumann@cs.unm.edu wrote:
On Tue, 1 Nov 2005, Matt Mower wrote: Yeah... one of the great problems with Haskell is the relative paucity of "Haskell for n00bs" type documentation. A couple of good sources are Two Dozen Short Lessons in Haskell [1], and Yet Another Haskell Tutorial [2] (note that Two Dozen uses hugs, not ghci).
Pressure of work means I won't have a chance to play with Haskell again until tomorrow evening or Friday but I didn't want to leave it that long to thank you for the detailed responses -- hopefully with this advice I can get going :-)
Regards,
Matt
-- Matt Mower :: http://matt.blogs.it/
Matt,
If you are trying to use ghci or similar, You probably ran into the same problem I did when I started trying the tutorials. Apparently you can not define functions in the interactive Haskell environment. The tutorials are not clear on that, and I really don't understand why you can't do that.
Brad
On Nov 1, 2005, at 11:27 AM, Matt Mower wrote:
Hi Scott,
On 01/11/05, Scott Barron scott@elitists.net wrote:
On Oct 31, 2005, at 6:06 PM, Matt Mower wrote:
Anyone working on a bundle for Haskell?
Indeed, Jamis Buck just blogged about starting one!
That's great, many thanks for the link. It may actually have been one of Jamis' posts that got me to take a (first) look at Haskell last night.
So far I can't actually get any code to run in the GHC interpreter, something about my functions not being in scope... a most confusing start, worse even than Lisp :-)
Regards,
Matt
-- Matt Mower :: http://matt.blogs.it/
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Hi,
In a somewhat vain attempt to make this relevant to Textmate, let me thank everyone for the pointer to the Haskell bundle: like a few people I was contemplating getting my hands dirty and constructing something similar, but hadn't yet got around to doing so.
If you are trying to use ghci or similar, You probably ran into the same problem I did when I started trying the tutorials. Apparently you can not define functions in the interactive Haskell environment. The tutorials are not clear on that, and I really don't understand why you can't do that.
You certainly can, but that's not the way in which ghci is really intended to work.
% ghci
[...banner deleted: OK, let's define a function to join an array of strings with another string, or "" if fed an empty array.]
Prelude> let join a []=""; join a x =foldr1 (\x y ->x++a++y) x
Prelude> join " me " ["Show","money","hearties"] "Show me money me hearties""
Even given this possibility, it probably more sense to write your functions/modules in a separate file and to reload that inside ghci. Just use
:l filename.hs
to load and a simple ":r" to reload after modifications. If you want to use Textmate to do the editing (surprise surprise) there's a shell escape available in ghci, so something like
:!mate filename.hs
allows a nice try/edit/try interface. That is, ghci is probably best viewed as *interactive* in the sense that you're "driving" your program, rather than *writing* your program. It's also a great environment for testing out one-liners for inclusion in larger programs.
Cheers, Paul