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: Haskell book (Nadir Sampaoli)
2. confusing type signature with sections (Patrick Redmond)
3. Re: confusing type signature with sections (Keshav Kini)
4. Re: Libzip for Haskell under Window (Riaan)
5. Re: Libzip for Haskell under Window (Riaan)
6. Re: Haskell book (Heinrich Apfelmus)
7. Creating arrays in Haskell (Michal Kawalec)
----------------------------------------------------------------------
Message: 1
Date: Tue, 1 Oct 2013 20:58:46 +0200
From: Nadir Sampaoli <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Haskell book
Message-ID:
<CAFYwTdT3qZj+jP1Qb5w5omOmcFAysk=b_vx8fdaz6_5eyer...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
aside from the excellent resources already cited, I'd like to add a link to
a blog post about Monads, Functors and
Applicatives<http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html>by
Aditya Bhargava. It really clarified the concept. Also, those pictures
are amazing!
--
Nadir
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131001/613eae25/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 1 Oct 2013 20:25:18 -0400
From: Patrick Redmond <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] confusing type signature with sections
Message-ID:
<CAHUea4Ff=BsbLJEa8dtW8kjWTQ9xQ5Ake=7hkyzlwpnmuy+...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
I wrote code to shift and scale the range [-1, 1] to [0, 1] and mapped
it on a list.
Prelude> map (\n -> ((n + 1) / 2)) [-1, 0, 1]
[0.0,0.5,1.0]
I thought using sections would better express the simplicity of this operation.
Prelude> :t (+ 1)
(+ 1) :: Num a => a -> a
Prelude> :t (/ 2)
(/ 2) :: Fractional a => a -> a
Given the types of those sections, I thought it sensible for me to
compose them like this.
Prelude> :t ((+ 1) / 2)
((+ 1) / 2) :: (Fractional (a -> a), Num a) => a -> a
This didn't work of course, and its type baffles me. Though it ends
with "Num a) => a -> a", it gives an error when given a number. I
don't understand what "(Fractional (a -> a), ...) =>" really means. It
seems like I've asked Haskell to perform "/" on the arguments "(+ 1)"
and "2", but that ought to be disallowed by the type of "/".
I eventually realized I should use the composition operator (below),
but I'm still curious what I created with "((+ 1) / 2)".
Prelude> :t (/ 2) . (+ 1)
(/ 2) . (+ 1) :: Fractional c => c -> c
Thanks!
Patrick
------------------------------
Message: 3
Date: Tue, 01 Oct 2013 19:47:35 -0500
From: Keshav Kini <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] confusing type signature with
sections
Message-ID: <[email protected]>
Content-Type: text/plain
Patrick Redmond <[email protected]> writes:
> I wrote code to shift and scale the range [-1, 1] to [0, 1] and mapped
> it on a list.
>
> Prelude> map (\n -> ((n + 1) / 2)) [-1, 0, 1]
> [0.0,0.5,1.0]
>
> I thought using sections would better express the simplicity of this
> operation.
>
> Prelude> :t (+ 1)
> (+ 1) :: Num a => a -> a
>
> Prelude> :t (/ 2)
> (/ 2) :: Fractional a => a -> a
>
> Given the types of those sections, I thought it sensible for me to
> compose them like this.
>
> Prelude> :t ((+ 1) / 2)
> ((+ 1) / 2) :: (Fractional (a -> a), Num a) => a -> a
>
> This didn't work of course, and its type baffles me. Though it ends
> with "Num a) => a -> a", it gives an error when given a number. I
> don't understand what "(Fractional (a -> a), ...) =>" really means. It
> seems like I've asked Haskell to perform "/" on the arguments "(+ 1)"
> and "2", but that ought to be disallowed by the type of "/".
Well, what is the type of (/) ?
Prelude> :t (/)
(/) :: Fractional a => a -> a -> a
By writing ((+ 1) / 2), you are indeed dividing (+ 1) by 2. You can
divide any two things of some type a, as long as that type is a
fractional type. Here your two things are (+ 1), which is of type (Num
a) => a -> a, and 2, which is of type (Num a') => a'. (Here I've added
prime symbols to distinguish between the type variables in the two type
signatures, as they are not necessarily the same when you put the two
expressions together into the same context.)
Now, because we are writing ((+ 1) / 2) and we know that (/) takes two
arguments that must be of the same type, we know that the type (Num a')
=> a' -> a' and the type (Num a'') => a'' have to be the same type, so
it must be that a' = a -> a, so now we have:
(+ 1) :: (Num a, Num (a -> a)) => a -> a
2 :: (Num a, Num (a -> a)) => a -> a
Furthermore, since (/) not only takes two arguments that are of the same
type but also requires that this type must be Fractional, we actually
have
(+ 1) :: (Num a, Num (a -> a), Fractional (a -> a)) => a -> a
2 :: (Num a, Num (a -> a), Fractional (a -> a)) => a -> a
But the Fractional typeclass actually is a subset of the Num typeclass
(that is, a type must be a Num type before it can be a Fractional
type). So the first "Num (a -> a)" is redundant. Thus we finally get
(+ 1) :: (Num a, Fractional (a -> a)) => a -> a
2 :: (Num a, Fractional (a -> a)) => a -> a
(/) :: (Num a, Fractional (a -> a)) => (a -> a) -> (a -> a) -> a -> a
((+ 1) / 2) :: (Num a, Fractional (a -> a)) => a -> a
Hopefully that makes more sense.
-Keshav
------------------------------
Message: 4
Date: Wed, 2 Oct 2013 13:26:00 +1000
From: Riaan <[email protected]>
To: Henk-Jan van Tuyl <[email protected]>
Cc: [email protected]
Subject: Re: [Haskell-beginners] Libzip for Haskell under Window
Message-ID:
<CAGHWPqpfitF1QrfvzjA6xQJSbrx9xKaT=8-ygayoc-0yvfk...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thank you for the advice - I got libzip compiled using MinGW but now I am
struggling to get cabal to find it, it seems that pkg-config can't detect
it. I have it in the default locations: /usr/local/include and
/usr/local/lib inside the MinGW shell.
Any suggestions?
On Tue, Oct 1, 2013 at 9:43 PM, Henk-Jan van Tuyl <[email protected]> wrote:
> On Tue, 01 Oct 2013 11:10:18 +0200, Riaan <[email protected]> wrote:
>
> I have not been able to figure out how to get libzip [
>> http://www.nih.at/libzip/**index.html<http://www.nih.at/libzip/index.html>]
>> installed under windows so that cabal
>> can install the package.
>>
>> I don't seem to be able to find a compiled binary anywhere. Can anyone
>> help?
>>
>
> You will have to compile the C package yourself, using MinGW (see the
> HaskellWiki page for Windows[0]). Start the MinGW shell with command 'sh'
> and follow the instructions in the file INSTALL.
>
> Regards,
> Henk-Jan van Tuyl
>
> [0]
> http://www.haskell.org/**haskellwiki/Windows#Tools_for_**compilation<http://www.haskell.org/haskellwiki/Windows#Tools_for_compilation>
>
>
> --
> Folding@home
> What if you could share your unused computer power to help find a cure? In
> just 5 minutes you can join the world's biggest networked computer and get
> us closer sooner. Watch the video.
> http://folding.stanford.edu/
>
>
> http://Van.Tuyl.eu/
> http://members.chello.nl/**hjgtuyl/tourdemonad.html<http://members.chello.nl/hjgtuyl/tourdemonad.html>
> Haskell programming
> --
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131002/345b888e/attachment-0001.html>
------------------------------
Message: 5
Date: Wed, 2 Oct 2013 16:51:15 +1000
From: Riaan <[email protected]>
To: Henk-Jan van Tuyl <[email protected]>
Cc: [email protected]
Subject: Re: [Haskell-beginners] Libzip for Haskell under Window
Message-ID:
<caghwpqoqdegrswzqfzzjv8fgkzcjjoiqv0mu_tgvvil0ue4...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Don't worry. I found the problem. After installing LibZip I needed to set
PKG_CONFIG_PATH to point to /usr/local/lib/pkgconfib.
All good now, thank you for the help
On Wed, Oct 2, 2013 at 1:26 PM, Riaan <[email protected]> wrote:
> Thank you for the advice - I got libzip compiled using MinGW but now I am
> struggling to get cabal to find it, it seems that pkg-config can't detect
> it. I have it in the default locations: /usr/local/include and
> /usr/local/lib inside the MinGW shell.
>
> Any suggestions?
>
>
>
>
> On Tue, Oct 1, 2013 at 9:43 PM, Henk-Jan van Tuyl <[email protected]>wrote:
>
>> On Tue, 01 Oct 2013 11:10:18 +0200, Riaan <[email protected]> wrote:
>>
>> I have not been able to figure out how to get libzip [
>>> http://www.nih.at/libzip/**index.html<http://www.nih.at/libzip/index.html>]
>>> installed under windows so that cabal
>>> can install the package.
>>>
>>> I don't seem to be able to find a compiled binary anywhere. Can anyone
>>> help?
>>>
>>
>> You will have to compile the C package yourself, using MinGW (see the
>> HaskellWiki page for Windows[0]). Start the MinGW shell with command 'sh'
>> and follow the instructions in the file INSTALL.
>>
>> Regards,
>> Henk-Jan van Tuyl
>>
>> [0]
>> http://www.haskell.org/**haskellwiki/Windows#Tools_for_**compilation<http://www.haskell.org/haskellwiki/Windows#Tools_for_compilation>
>>
>>
>> --
>> Folding@home
>> What if you could share your unused computer power to help find a cure?
>> In just 5 minutes you can join the world's biggest networked computer and
>> get us closer sooner. Watch the video.
>> http://folding.stanford.edu/
>>
>>
>> http://Van.Tuyl.eu/
>> http://members.chello.nl/**hjgtuyl/tourdemonad.html<http://members.chello.nl/hjgtuyl/tourdemonad.html>
>> Haskell programming
>> --
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131002/1a2a7edc/attachment-0001.html>
------------------------------
Message: 6
Date: Wed, 02 Oct 2013 11:07:58 +0200
From: Heinrich Apfelmus <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Haskell book
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Michael Loegering wrote:
> I am looking for a general Haskell book with syntax reference to
> self-teach. I have a computer science background, so technical and
> theoretical is fine. Something similar in size and scope as the Camel book
> is to perl would be ideal - covering basic language idioms, with a decent
> language reference, but by no means exhaustive.
>
> I have looked at Learn You a Haskell and Real World Haskell online, both of
> which were accessible but were difficult to follow beyond the basics. I'm
> not sure if it's the organization of the material or just the learning
> curve, so I'm open to both if these are hands-down the favorites.
I can also recommend
Graham Hutton. Programming in Haskell.
http://www.cs.nott.ac.uk/~gmh/book.html
It's basically a rendition of Graham's lecture notes, which means that
it's clear and to the point. It's not as cute as Learn You a Haskell,
but the scope is similar.
If you're completely new to Haskell and you have a background in
imperative programming and you're not a mathematician, then you will
need to tackle the learning curve by doing exercises. Haskell is not
another imperative language with slightly different syntax, it's more
like learning programming anew.
Best regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 7
Date: Wed, 02 Oct 2013 10:51:52 +0100
From: Michal Kawalec <[email protected]>
To: beginners <[email protected]>
Subject: [Haskell-beginners] Creating arrays in Haskell
Message-ID: <1380707376-sup-6173@carrot>
Content-Type: text/plain; charset="utf-8"
Hello,
I want to use the FFT library in Haskell and for that I need to create
an array. However, when I input
array (1,100) [(i, i*i) | i <- [1..100]]
in ghci, I get an error saying:
No instance for (Enum e0)
arising from the arithmetic sequence `1 .. 100'
The type variable `e0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Enum Double -- Defined in `GHC.Float'
instance Enum Float -- Defined in `GHC.Float'
instance Integral a => Enum (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
...plus 15 others
In the expression: [1 .. 100]
In a stmt of a list comprehension: i <- [1 .. 100]
In the second argument of `array', namely
`[(i, i * i) | i <- [1 .. 100]]'
Could you please tell me how to add the type signature?
--
Michal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131002/fd3512aa/attachment.sig>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 64, Issue 4
****************************************