Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Searching Maybe lists (Heinrich Apfelmus)
2. Intervals? (Nathan Holden)
3. Re: Intervals? (Edward Z. Yang)
4. Re: Intervals? (Nathan Holden)
5. Re: Intervals? (Edward Z. Yang)
6. Re: Intervals? (aditya siram)
7. "computation", "action" (Michael P Mossey)
8. Re: "computation", "action" (Andrew Wagner)
----------------------------------------------------------------------
Message: 1
Date: Tue, 19 May 2009 18:45:25 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Searching Maybe lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
aditya siram wrote:
>>
>>
>> You will have to write orMaybe as
>>
>> orMaybe Nothing y = y
>> orMaybe x _ = x
>>
>> though. (By the way, your original code for orMaybe doesn't seem to do
>> what you want.) This function has already been implemented for you, it's
>> called
>>
>> mplus
>
>
> My function 'orMaybe' takes two arguments m1 m2, if one of them is Nothing,
> it returns Nothing, if m1 is Just , it returns m1, if m2 is Just, it returns
> m2. This seems to be what I want. Why is this incorrect?
Ah, you're right, my bad. I was confused by the fact that you were using
it from right to left, i.e.
findMaybe f = foldr (\a sofar -> sofar `orMaybe` a) Nothing . map f
= foldr (flip orMaybe) Nothing . map f
instead of
findMaybe f = foldr orMaybe Nothing . map f
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 2
Date: Tue, 19 May 2009 14:43:04 -0400
From: Nathan Holden <[email protected]>
Subject: [Haskell-beginners] Intervals?
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I have been trying to optimize some research I was doing in my spare time.
To spare complexity, it involves music-- I have a class, defining each note
in an octave, and I want to write a function that will convert between two
notes and an interval-- so, for instance:
Foo As {- A sharp-- can't use # -} B = 1
because in the standard scale, A# and B are one semitone apart.
My question, however, boils primarily down to this: Is there a way to make
Foo :: Note -> Note -> Int
Foo a b = a-b
work?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090519/c6e23588/attachment-0001.html
------------------------------
Message: 3
Date: Tue, 19 May 2009 14:53:36 -0400
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] Intervals?
To: beginners <[email protected]>
Message-ID: <1242759184-sup-8...@javelin>
Content-Type: text/plain; charset=UTF-8
Excerpts from nathanmholden's message of Tue May 19 14:43:04 -0400 2009:
> My question, however, boils primarily down to this: Is there a way to make
>
> Foo :: Note -> Note -> Int
> Foo a b = a-b
A sensible implementation of the Num typeclass for Note should do the
trick nicely.
Cheers,
Edward
------------------------------
Message: 4
Date: Tue, 19 May 2009 15:07:26 -0400
From: Nathan Holden <[email protected]>
Subject: Re: [Haskell-beginners] Intervals?
To: Derek Gladding <[email protected]>, [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Yeah, it would. But I always write code like that, it feels ungainly...
writing super-long, case-by-case instance declarations (So that I can add in
one little caveat at the end, or something), and stuff. Makes me feel like I
must be dumb!
On Tue, May 19, 2009 at 2:54 PM, Derek Gladding <[email protected]> wrote:
> Nathan Holden wrote:
>
>> [snip]
>> My question, however, boils primarily down to this: Is there a way to make
>>
>> Foo :: Note -> Note -> Int
>> Foo a b = a-b
>>
>> work?
>>
>
> Would a function
>
> Bar :: Note -> Int
>
> make writing Foo easier?
>
> - Derek
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090519/c7112916/attachment-0001.html
------------------------------
Message: 5
Date: Tue, 19 May 2009 15:16:36 -0400
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] Intervals?
To: beginners <[email protected]>
Message-ID: <1242760523-sup-1...@javelin>
Content-Type: text/plain; charset=UTF-8
Excerpts from nathanmholden's message of Tue May 19 15:07:26 -0400 2009:
> Yeah, it would. But I always write code like that, it feels ungainly...
> writing super-long, case-by-case instance declarations (So that I can add in
> one little caveat at the end, or something), and stuff. Makes me feel like I
> must be dumb!
It seems to me, in this particular case, that you don't actually want an
algebraic datatype (which seems to be what you're implementation is using).
Cheers,
Edward
------------------------------
Message: 6
Date: Tue, 19 May 2009 14:43:04 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Intervals?
To: Nathan Holden <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
How about something like this?
import Data.List
data Note = C | Cs | D | Eb | E | F | Fs | G | Ab | A | Bb | B deriving Enum
--Counting forward from n1 to n2
interval :: Note -> Note -> Int
n1 `interval` n2 = (12 - fromEnum n1) + fromEnum n2
--Counting back from n2 to n1
bInterval :: Note -> Note -> Int
n1 `bInterval` n2 = fromEnum n1 - fromEnum n2
testInterval = A `interval` D
testBInterval = A `bInterval` D
I don't see how these operations could be made part of the Num because the
output of the Num class has to be the same as the input. For instance, when
adding two numbers, the output is a number, but for determining intervals,
the inputs are Notes and the output is a number.
-deech
On Tue, May 19, 2009 at 1:43 PM, Nathan Holden <[email protected]>wrote:
> I have been trying to optimize some research I was doing in my spare time.
>
> To spare complexity, it involves music-- I have a class, defining each note
> in an octave, and I want to write a function that will convert between two
> notes and an interval-- so, for instance:
>
> Foo As {- A sharp-- can't use # -} B = 1
>
> because in the standard scale, A# and B are one semitone apart.
>
> My question, however, boils primarily down to this: Is there a way to make
>
> Foo :: Note -> Note -> Int
> Foo a b = a-b
>
> work?
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090519/0cb9f5fa/attachment-0001.html
------------------------------
Message: 7
Date: Tue, 19 May 2009 15:14:12 -0700
From: Michael P Mossey <[email protected]>
Subject: [Haskell-beginners] "computation", "action"
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I've seen the following language used:
- "computations"
- "actions"
- "effects"
- "context" (For example, a functor is a context, and fmap applies a function
to
an object in that context without changing the context.)
One words that seem to come up in Haskell are "algorithm" and "procedure."
For example, a monad is sometimes called a "computation" or an "effect", but
I've not seen it called an "algorithm."
Can someone elaborate on these terms and why they are used? What is the
difference between a computation and an algorithm? The word "effect" has a
fairly obvious meaning (like an IO side-effect) but I suspect there's more to
it.
Why is the word "context" important, and when it is more appropriate than
"container"?
thanks,
Mike
------------------------------
Message: 8
Date: Tue, 19 May 2009 18:21:50 -0400
From: Andrew Wagner <[email protected]>
Subject: Re: [Haskell-beginners] "computation", "action"
To: Michael P Mossey <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Tue, May 19, 2009 at 6:14 PM, Michael P Mossey
<[email protected]>wrote:
> I've seen the following language used:
> - "computations"
> - "actions"
> - "effects"
> - "context" (For example, a functor is a context, and fmap applies a
> function to an object in that context without changing the context.)
>
These are all often used to describe expressions of type "m a" for some
monad m. Different ones are more or less accurate depending on the
particular monad you're talking about, and depending on your personal
preferred way of looking at it. The thing with monads is that what they
abstract is hard to put succinctly outside of code.
>
> One words that seem to come up in Haskell are "algorithm" and "procedure."
>
I've not seen these used in Haskell. They sound distinctly imperative to me,
for some reason. But, until you define the words connotatively, all I can
say is how they sound to me.
>
> For example, a monad is sometimes called a "computation" or an "effect",
> but I've not seen it called an "algorithm."
>
> Can someone elaborate on these terms and why they are used? What is the
> difference between a computation and an algorithm? The word "effect" has a
> fairly obvious meaning (like an IO side-effect) but I suspect there's more
> to it.
>
> Why is the word "context" important, and when it is more appropriate than
> "container"?
>
I would put container in with the list at the beginning: it's another way
that can be more or less appropriate for monadic values, depending on the
monad and your perspective.
>
> thanks,
> Mike
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090519/e0f9a553/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 11, Issue 14
*****************************************