I am just beginning to learn Haskell. Just for starters I'm watching a video lecture from Channel 9. The lecturer defines a function like this "myadd (x,y) = x + y". When I enter this into GHCi I get the error message ":1:12: parse error on input `='". Could I get a simple explanation of this?
"Chris Saunders" <e...@mountaincable.net> writes: > I am just beginning to learn Haskell. Just for starters I'm watching a > video lecture from Channel 9. The lecturer defines a function like this > "myadd (x,y) = x + y". When I enter this into GHCi I get the error message > ":1:12: parse error on input `='". Could I get a simple explanation of > this?
When typing functions into GHCi, add a `let' in front:
Prelude> let myadd (x,y) = x + y Prelude> :info myadd myadd :: (Num t) => (t, t) -> t -- Defined at <interactive>:1:4-8 Prelude>
If you put it in a file instead and use :load to load it (or :reload to reload it), you don't put the `let' in the definition in the file.
I very much appreciate your help. I'm afraid I may be full of dumb questions for awhile. For a little while, I don't think I'll be trying to create any source files but I'll try to remember the tip.
>> I am just beginning to learn Haskell. Just for starters I'm watching a >> video lecture from Channel 9. The lecturer defines a function like this >> "myadd (x,y) = x + y". When I enter this into GHCi I get the error >> message >> ":1:12: parse error on input `='". Could I get a simple explanation of >> this?
> When typing functions into GHCi, add a `let' in front:
> Prelude> let myadd (x,y) = x + y > Prelude> :info myadd > myadd :: (Num t) => (t, t) -> t -- Defined at <interactive>:1:4-8 > Prelude>
> If you put it in a file instead and use :load to load it (or :reload to > reload it), you don't put the `let' in the definition in the file.
"Chris Saunders" <e...@mountaincable.net> writes: > I very much appreciate your help. I'm afraid I may be full of dumb > questions for awhile. For a little while, I don't think I'll be > trying to create any source files but I'll try to remember the tip.
IRC might be a better place than Usenet to seek this kind of help. If you have an IRC client, hang out on #haskell. It is a friendly place and you'll learn a lot.
"Chris Saunders" <e...@mountaincable.net> writes: > I very much appreciate your help. I'm afraid I may be full of dumb > questions for awhile. For a little while, I don't think I'll be trying to > create any source files but I'll try to remember the tip.
No problem, dumb questions are at least quickly answered. (-:
So what is this Channel 9 that teaches Haskell? Sounds intriguing.
Paul Rubin <http://phr...@NOSPAM.invalid> writes: > "Mark T. B. Carroll" <Mark.Carr...@Aetion.com> writes: >> So what is this Channel 9 that teaches Haskell? Sounds intriguing.
Oh, an online Microsoft community thing, thank you! And I had been wondering if it was some local public access station. (Ours happens to be on channel 9 on cable.)
"Chris Saunders" <e...@mountaincable.net> wrote: > I am just beginning to learn Haskell. Just for starters I'm watching > a video lecture from Channel 9. The lecturer defines a function like > this "myadd (x,y) = x + y". When I enter this into GHCi I get the > error message ":1:12: parse error on input `='". Could I get a simple > explanation of this?
Your original question has been answered. I just like to add something very important.
Simply put, this is not the way you would define a 'myAdd' function in Haskell. Your function doesn't take two arguments, but only one argument, a tuple of two numbers, notated by (x, y). Here is how to do it properly:
myAdd x y = x + y
What is the difference, you may ask. It's currying. If you define it the way you did, you lose the advantages of curried style, one of which is more concise source code, another one is partial application. You couldn't use the following statements:
myAdd 3 5 Results in 8, you would need to write myAdd (3, 5).
myAdd 3 Results in a function, which adds 3 to its argument. This is called partial application, one of the key features of currying.
3 `myAdd` 5 Infix notation for binary functions. Doesn't make sense for your definition, because your variant of myAdd takes only one argument, namely a tuple.
Functional programming tutorials on the MSDN are usually totally brain-damaged, even for Microsoft's own language F#. Even though F# supports currying, they don't promote its use and still use the obsolete uncurried style. It seems like the tutorial authors don't understand the language themselves. Interestingly even F#'s design is highly influenced by this incompetence, which makes the language frustrating to use, even though it would have potential.
I rather like this suggestion. I have never used IRC. Could you suggest a program to use on Windows. Right now I am having a few difficulties that I'm almost ashamed to ask about.
Regards Chris Saunders
"Paul Rubin" <http://phr...@NOSPAM.invalid> wrote in message
> "Chris Saunders" <e...@mountaincable.net> writes: >> I very much appreciate your help. I'm afraid I may be full of dumb >> questions for awhile. For a little while, I don't think I'll be >> trying to create any source files but I'll try to remember the tip.
> IRC might be a better place than Usenet to seek this kind of help. If > you have an IRC client, hang out on #haskell. It is a friendly place > and you'll learn a lot.
Chris Saunders <e...@mountaincable.net> wrote: > I rather like this suggestion. I have never used IRC. Could you suggest a > program to use on Windows. Right now I am having a few difficulties that > I'm almost ashamed to ask about.
Don't be ashamed, just ask. There are no dumb questions, just dumb answers.
I'm not using Windows, but AFAIK, "mirc" is a popular client for Windows.
Thanks for the tip. Perhaps the information on MSDN is not a brain damaged as you think. What you spoke about is described and spoken about in the lecture series I was watching. I was just trying to enter some of the example code shown into GHCi. I am reading the manual for GHCi but have not gotten very far with that yet.
Regards Chris Saunders
"Ertugrul Söylemez" <e...@ertes.de> wrote in message
>> I am just beginning to learn Haskell. Just for starters I'm watching >> a video lecture from Channel 9. The lecturer defines a function like >> this "myadd (x,y) = x + y". When I enter this into GHCi I get the >> error message ":1:12: parse error on input `='". Could I get a simple >> explanation of this?
> Your original question has been answered. I just like to add something > very important.
> Simply put, this is not the way you would define a 'myAdd' function in > Haskell. Your function doesn't take two arguments, but only one > argument, a tuple of two numbers, notated by (x, y). Here is how to do > it properly:
> myAdd x y = x + y
> What is the difference, you may ask. It's currying. If you define it > the way you did, you lose the advantages of curried style, one of which > is more concise source code, another one is partial application. You > couldn't use the following statements:
> myAdd 3 5 > Results in 8, you would need to write myAdd (3, 5).
> myAdd 3 > Results in a function, which adds 3 to its argument. This is called > partial application, one of the key features of currying.
> 3 `myAdd` 5 > Infix notation for binary functions. Doesn't make sense for your > definition, because your variant of myAdd takes only one argument, > namely a tuple.
> Functional programming tutorials on the MSDN are usually totally > brain-damaged, even for Microsoft's own language F#. Even though F# > supports currying, they don't promote its use and still use the obsolete > uncurried style. It seems like the tutorial authors don't understand > the language themselves. Interestingly even F#'s design is highly > influenced by this incompetence, which makes the language frustrating to > use, even though it would have potential.
Dirk Thierbach <dthierb...@usenet.arcornews.de> writes: > Chris Saunders <e...@mountaincable.net> wrote: >> I rather like this suggestion. I have never used IRC. Could you suggest a >> program to use on Windows. Right now I am having a few difficulties that >> I'm almost ashamed to ask about.
> Don't be ashamed, just ask. There are no dumb questions, just dumb answers.
Quite, if you're making a good effort to try, we'll still be able to tell even if the questions are dumb. And for what it's worth, I've asked my fair share of dumb questions too. (-:
"Mark T. B. Carroll" <Mark.Carr...@Aetion.com> writes:
> dumb questions are at least quickly answered.
For instance, seeing intersectBy, etc., I was just wondering aloud where differenceBy is, only for it to be pointed out to me that it's deleteFirstsBy. (In my defense, Hayoo was down at the time. (-:)