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:  What to do next? (bruce li)
   2. Re:  Haskell Weekly News (Zlatan Todoric)
   3. Re:  Question about define my own typeclass (Mateusz Kowalczyk)
   4. Re:  What does the "!n" mean? (John M. Dlugosz)
   5.  Cabal gives error (John M. Dlugosz)


----------------------------------------------------------------------

Message: 1
Date: Thu, 27 Mar 2014 11:50:28 -0400
From: bruce li <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] What to do next?
Message-ID:
        <cagmt-v5cmmecfqopmkuh0m9vxdfmue11m1kzpz+xh75sdvg...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Thanks for the exercises. I think I've finished all exercises except the
last 2 projects. But here are some questions regarding the exercises:

1. The layout of the typeclasses looks a bit different from Haskell, like
splitting applicative functor into apply and applicative. I wonder you
could tell me the reason.

2. How to write cooler code like  lift2 ((++) =<<) preillion postillion?
How could I make such usage a habit?

Thanks.



2014-03-20 18:15 GMT-04:00 Tony Morris <[email protected]>:

>  I teach FP for a living for an organisation called NICTA. This is the
> material I use primarily https://github.com/NICTA/course
>
> If you can do the easy stuff, fine. For example,
> https://github.com/NICTA/course/blob/master/src/Course/List.hs
> https://github.com/NICTA/course/blob/master/src/Course/ListZipper.hs
> https://github.com/NICTA/course/blob/master/src/Course/StateT.hs
>
> If you want it a bit harder:
> https://github.com/NICTA/course/blob/master/src/Course/Parser.hs
> https://github.com/NICTA/course/blob/master/src/Course/JsonParser.hs
> https://github.com/NICTA/course/blob/master/src/Course/Cheque.hs
>
> But if you can do any of these, then I would say you are not a beginner
> anymore:
>
> https://github.com/NICTA/course/blob/master/projects/TicTacToe/TicTacToe.markdown
>
> https://github.com/NICTA/course/blob/master/projects/NetworkServer/NetworkServer.markdown
>
>
>
> On 21/03/14 04:17, bruce li wrote:
>
> Hi, there,
> I'm relatively new to Haskell...well... I mean I haven't done anything I
> believe truely in Haskell. I have gone through materials like Learn You a
> Haskell for Real Good, Real World Haskell, most chapters in Haskell
> Wikibook, Write Yourself Scheme in 48 Hours, Algorithms: A Functional
> Approach and other materials in Haskell Wiki.
>
>  *But... what I feel is that I'm not confident while writing Haskell
> code.* Having gone through all those materials with "magic", I always
> feel I'm writing stupid code and there must be more elegant way... And...
> what's worse, I feel guilty while using IO monad but I simply cannot avoid
> it, like when I try to write code generator for a toy compiler, I need to
> keep state of the registers, which I need IORef... Then I feel its not pure
> anymore but I don't know how to get around it.
>
>  I'm wondering if anyone else shares this kind of feeling and what should
> I do next? Could anyone suggest any project to get hands on experience with
> Haskell?
>
>  Another question is that the deeper digging into functional algorithms
> design (reading the book Pearls of Functional Algorithm Design), the more
> ignorant I feel. So how do I make up the basics like fold law, list
> induction etc. Any suggested reading materials?
>
>  Well.. I think that's a lot question. Thanks for your patience and your
> kind help.
>
>
> _______________________________________________
> Beginners mailing 
> [email protected]http://www.haskell.org/mailman/listinfo/beginners
>
>
>
> --
> Tony Morrishttp://tmorris.net/
>
>
> _______________________________________________
> 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/20140327/6202686b/attachment-0001.html>

------------------------------

Message: 2
Date: Thu, 27 Mar 2014 17:21:57 +0100
From: Zlatan Todoric <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Weekly News
Message-ID:
        <cankatb1nxaorvdfof3hytrvg5pgs1qgfynprdpc2uukpsug...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I am new on list but I would certainly like to see
HWN :)


On Thu, Mar 27, 2014 at 4:24 PM, Darren Grant <[email protected]> wrote:

> Indeed thank you for the HWNs of the past! I miss them too. :-)
>
> Cheers,
> Darren
> On Mar 27, 2014 8:21 AM, "Thiago Negri" <[email protected]> wrote:
>
>> +1
>>
>>
>> 2014-03-27 10:01 GMT-03:00 Alexander Berntsen <[email protected]>:
>>
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA256
>>>
>>> On 27/03/14 13:55, Amy de Buitl?ir wrote:
>>> > I miss HWN.
>>> +1
>>>
>>> I assume the editor doesn't have time for it any longer, but maybe
>>> they'll find it encouraging that we miss it at least. :-)
>>>
>>> - --
>>> Alexander
>>> [email protected]
>>> https://secure.plaimi.net/~alexander
>>> -----BEGIN PGP SIGNATURE-----
>>> Version: GnuPG v2.0.22 (GNU/Linux)
>>> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>>>
>>> iF4EAREIAAYFAlM0IRwACgkQRtClrXBQc7UYEwEAqMUsZVGebIlmhNN7nj8OgL3g
>>> uaa1zGgdKjonmmaRoAwA/24yBCbkCyEQix2SyMJvomZdAnnUQaBCQggyB7pADZmf
>>> =sDi+
>>> -----END PGP SIGNATURE-----
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
Please while sending me text documents pay attention that they are by ISO
standard that is in .odt format (For sending other types of documents
please also refer to ISO/Open standars).
Its not the COST, its the VALUE!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140327/3f6b9f82/attachment-0001.html>

------------------------------

Message: 3
Date: Thu, 27 Mar 2014 16:36:12 +0000
From: Mateusz Kowalczyk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Question about define my own
        typeclass
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On 27/03/14 15:49, ke dou wrote:
> Thanks for your reply.
> 
> Yes, I understand that if I specify the 'b' to 'Prelude.Bool', it should
> work, but what if I also want use the typeclass Conversion to convert other
> types other than MyBool, like MyInt, or MyString?
> 
> --Ke
> 
> On Thu, Mar 27, 2014 at 11:36 AM, Brandon Allbery <[email protected]>wrote:
> 
>> On Thu, Mar 27, 2014 at 11:28 AM, ke dou <[email protected]> wrote:
>>
>>>     class Conversion a where
>>>         conversion :: a  -> b
>>>
>>
>> b is completely unspecified here, since it's not defined as part of the
>> typeclass. The literal meaning of this is that "the caller can request any
>> type it pleases, and you have no way of knowing what it is". So the only
>> possible result of `conversion` is bottom (e.g. `undefined`).
>>
>> This is key: it does NOT mean that `conversion` gets to specify the result
>> type! You can't do that, except by specifying the type in the type
>> signature.
>>
>> --
>> brandon s allbery kf8nh                               sine nomine
>> associates
>> [email protected]
>> [email protected]
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
> 

This post is Literate Haskell.

You can specify which type you can coerce to by having the typeclass
also specify ?b?.

To have more than one type parameter, you'll need the MultiParamTypeClasses
language extension. Ignore FunctionalDependencies for now.

> {-# LANGUAGE FunctionalDependencies #-}
> {-# LANGUAGE MultiParamTypeClasses #-}
> {-# LANGUAGE UnicodeSyntax #-}
> module C where

First we define our own Bool for demonstration purposes.

> data MyBool = MyTrue | MyFalse

We define the class that also specifies ?b? as follows.

> class SimpleCoercible a b where
>   coerceSimple ? a ? b

We can now achieve what you want: we can state that ?a? cana be
coerced into ?b?. Here we state that we can convert to Haskell's Bool.

> instance SimpleCoercible MyBool Bool where
>   coerceSimple MyTrue = True
>   coerceSimple MyFalse = False

This works fine:

*C> coerceSimple MyTrue :: Bool
True

Note that I had to say what output type I wanted here because I'm not
using it
in a context that GHC could use to infer it. Just because there's only a
single
instance does not matter as anyone could come around and add a new
instance. In
fact, let's define one more just to show that you can do it. Let's go
with the
old 0 is True and 1 is False.

> instance SimpleCoercible MyBool Integer where
>   coerceSimple MyTrue = 0
>   coerceSimple MyFalse = 1

As you can see below, it all works great:

*C> coerceSimple MyTrue :: Integer
0
*C> coerceSimple MyTrue :: Bool
True


Now for something a bit out of scope of the question:

Now what if we wanted to only have a single possible mapping? Say, we
only want
MyBool to be coercible to Bool and nothing else? We can use
FunctionalDependencies language extension. I recommend you look it up if
you're
interested, here's an example:


> class CoercibleOneWay a b | a ? b where
>   coerceOneWay ? a ? b
>
> instance CoercibleOneWay MyBool Bool where
>   coerceOneWay MyTrue = True
>   coerceOneWay MyFalse = False

You might wonder if there's an advantage to doing such a thing. Well,
yes, GHC
now always knows what the output type (b) should be just by looking by
the input
type (a):

*C> :t coerceOneWay MyTrue
coerceOneWay MyTrue :: Bool

Note that this is not the case with our previous definition! GHC doesn't
know
exactly which ?b? we want:

*C> :t coerceSimple MyTrue
coerceSimple MyTrue :: SimpleCoercible MyBool b => b


Can we do more than this? What if we wanted to be able to coerce the
types the
other way too? We could write an instance for
?CoercibleOneWay Bool MyBool | b ? a? but that's unwieldy. We can
instead have
a single type class which can take us both ways:

> class Coercible a b | a ? b, b ? a where
>   coerceTo ? a ? b
>   coerceFrom ? b ? a
>
> instance Coercible MyBool Bool where
>   coerceTo MyTrue = True
>   coerceTo MyFalse = False
>
>   coerceFrom True = MyTrue
>   coerceFrom False = MyFalse

This now lets us convert between MyBool and Bool freely:

*C> :t coerceTo MyTrue
coerceTo MyTrue :: Bool
*C> :t coerceFrom True
coerceFrom True :: MyBool

With this you can model 1-to-1 mapping between your types and built-in
types.

Note that another approach would simply be to add an instance for
?CoercibleOneWay Bool MyBool?. A nice thing about this approach is that
you can
use the overloaded function name:

> instance CoercibleOneWay Bool MyBool where
>   coerceOneWay True = MyTrue
>   coerceOneWay False = MyFalse

*C> :t coerceOneWay True
coerceOneWay True :: MyBool
*C> :t coerceOneWay MyTrue
coerceOneWay MyTrue :: Bool

I think it's a matter of preference as to which way you go.


-- 
Mateusz K.


------------------------------

Message: 4
Date: Thu, 27 Mar 2014 14:32:50 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] What does the "!n" mean?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 3/26/2014 8:26 PM, yi lu wrote:
> http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/bang-patterns.html
>
> Do you mean this?

Thanks!  I missed it when scanning through the GHC docs.




------------------------------

Message: 5
Date: Thu, 27 Mar 2014 14:58:46 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Cabal gives error
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

When running cabal, it tells me
        Note: there is a new version of cabal-install available.
        To upgrade, run: cabal install cabal-install

And when I do that, it does a bunch of stuff and then

[68 of 70] Compiling Distribution.Simple.Bench ( 
E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\Distribution\Simple\Bench.hs, 
E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18
.1.3\dist\setup\Distribution\Simple\Bench.o )
[69 of 70] Compiling Distribution.Simple ( 
E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\Distribution\Simple.hs, 
E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\dist\setup\Distribution\Simple.o )
[70 of 70] Compiling Main             ( 
E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\Setup.hs, 
E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\dist\setup\Main.o )
Linking E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\dist\setup\setup.exe ...
Configuring Cabal-1.18.1.3...
setup.exe: does not exist
Failed to install Cabal-1.18.1.3
cabal: Error: some packages failed to install:
Cabal-1.18.1.3 failed during the configure step. The exception was:
ExitFailure 1
cabal-install-1.18.0.3 depends on Cabal-1.18.1.3 which failed to install.

[C:\Program Files (x86)\Haskell-Platform]

This is, as I recall, where I got stuck trying to get a newer Leksah installed.

Upon finishing, it deletes the temp directory tree, so I can't see if there's 
anything 
obviously strange with the file it produced.

How do I troubleshoot this?



------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 69, Issue 40
*****************************************

Reply via email to