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: Pound character use in code? (Brandon Allbery)
2. How to divide a pair of Num values? (Costello, Roger L.)
----------------------------------------------------------------------
Message: 1
Date: Tue, 23 Oct 2012 09:09:25 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Pound character use in code?
To: "M.v.Gulik" <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<cakfcl4xflkj2f-8mbstbxviq_unyg7vn2hm1wwj8boxso4e...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Tue, Oct 23, 2012 at 4:31 AM, M.v.Gulik <[email protected]> wrote:
> 1) What is the purpose of the used pound/"#" character here. (Looks
> like some type-casting, but that's just a wild guess from me here.
>
This is not normal Haskell code you're looking at; it's using internals
which are normally hidden, and # is not special in normal Haskell code. If
you turn on the special meaning (MagicHash) then it usually means that
something is unlifted.
In this case, 1# is an unboxed Int value: a raw machine word.
> 2) kinda the same for the "I#" in the "len [] ..." line. As the length
>
I# is the internal constructor for a normal Int value; the value (1 :: Int)
is internally represented as (I# 1#), or the internal Int constructor
wrapping a raw machine word.
> 3) Why is it giving a compile error on the "where" line. Error:
>
Because # does not have its special meaning in normal Haskell code.
http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#magic-hashdocuments
this special behavior, and what you need to do to get it. But
you should probably not be worrying about it at this point, and almost
certainly not using it.
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix/linux, openafs, kerberos, infrastructure http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121023/3068d907/attachment-0001.htm>
------------------------------
Message: 2
Date: Wed, 24 Oct 2012 09:01:34 +0000
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] How to divide a pair of Num values?
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi Folks,
Here is a function that takes a pair of Integral
values and divides them:
divide_v1 :: Integral a => (a, a) -> a
divide_v1 (m, n) = (m + n) `div` 2
I invoke the function with a pair of Integral
values and it works as expected:
divide_v1 (1, 3)
Great. That's perfect if my numbers are always Integrals.
Here is a function that takes a pair of Fractional
values and divides them:
divide_v2 :: Fractional a => (a, a) -> a
divide_v2 (m, n) = (m + n) / 2
I invoke the function with a pair of Fractional
values and it works as expected:
divide_v2 (1.0, 3.0)
Great. That's perfect if my numbers are always Fractionals.
I would like a function that works regardless of whether the
numbers are Integrals or Fractionals:
divide_v3 :: Num a => (a, a) -> a
divide_v3 (m, n) = (m + n) ___ 2
What operator do I use for ___?
Thanks.
/Roger
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 52, Issue 28
*****************************************