Beginners Digest, Vol 57, Issue 25

2013-03-18 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

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
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  type vs data, again... (Emmanuel Touzery)
   2. Re:  type vs data, again... (David McBride)
   3. Re:  type vs data, again... (Emmanuel Touzery)
   4. Re:  Confused about lazy IO (Kim-Ee Yeoh)


--

Message: 1
Date: Sun, 17 Mar 2013 16:16:41 +0100
From: Emmanuel Touzery 
Subject: Re: [Haskell-beginners] type vs data, again...
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Message-ID:

Content-Type: text/plain; charset="iso-8859-1"

Thank you, that was the trick! It would be handy it there was a way through
the online hackage packages pages to click through the dependencies. I
guess you checked the .cabal by hand or used some slightly more arcane
cabal commands to get that information.

Thank you again and nice rest of week-end!

Emmanuel


On Sun, Mar 17, 2013 at 2:51 PM, Andres L?h  wrote:

> Hi again.
>
> >  thank you for the tip! It helps but it's not quite there yet. If you see
> > the program in attachment, I can make it compile only by commenting the
> type
> > declaration for the second function, otherwise it's the exact same error
> > message as before.
>
> You're probably using the wrong HashMap. There are several packages on
> Hackage implementing similarly-named data structures (which is
> confusing, I know, but such is life in a decentralized and open
> world). You should use what aeson is using (because that's the library
> defining the Object type synonym).
>
> Looking at the import list of
>
>
> http://hackage.haskell.org/packages/archive/aeson/0.6.0.2/doc/html/src/Data-Aeson-Types-Internal.html
>
> we see
>
> import Data.HashMap.Strict (HashMap)
>
> and by checking the package dependencies of aeson, we figure out that
> this module is provided by the unordered-containers package.
>
> Cheers,
>   Andres
>
> --
> Andres L?h, Haskell Consultant
> Well-Typed LLP, http://www.well-typed.com
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sun, 17 Mar 2013 11:25:29 -0400
From: David McBride 
Subject: Re: [Haskell-beginners] type vs data, again...
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Message-ID:

Content-Type: text/plain; charset=ISO-8859-1

If you hover over "type Object = HashMap Text Value" in
Data.Aeson.Types in hackage, you will see that the HashMap link links
to 
http://hackage.haskell.org/packages/archive/unordered-containers/0.2.3.0/doc/html/Data-HashMap-Strict.html#t:HashMap,
which tells you what package it came from and what to import.

On Sun, Mar 17, 2013 at 11:16 AM, Emmanuel Touzery  wrote:
> Thank you, that was the trick! It would be handy it there was a way through
> the online hackage packages pages to click through the dependencies. I guess
> you checked the .cabal by hand or used some slightly more arcane cabal
> commands to get that information.
>
> Thank you again and nice rest of week-end!
>
> Emmanuel
>
>
> On Sun, Mar 17, 2013 at 2:51 PM, Andres L?h  wrote:
>>
>> Hi again.
>>
>> >  thank you for the tip! It helps but it's not quite there yet. If you
>> > see
>> > the program in attachment, I can make it compile only by commenting the
>> > type
>> > declaration for the second function, otherwise it's the exact same error
>> > message as before.
>>
>> You're probably using the wrong HashMap. There are several packages on
>> Hackage implementing similarly-named data structures (which is
>> confusing, I know, but such is life in a decentralized and open
>> world). You should use what aeson is using (because that's the library
>> defining the Object type synonym).
>>
>> Looking at the import list of
>>
>>
>> http://hackage.haskell.org/packages/archive/aeson/0.6.0.2/doc/html/src/Data-Aeson-Types-Internal.html
>>
>> we see
>>
>> import Data.HashMap.Strict (HashMap)
>>
>> and by checking the package dependencies of aeson, we figure out that
>> this module is provided by the unordered-containers package.
>>
>> Cheers,
>>   Andres
>>
>> --
>> Andres L?h, Haskell Consultant
>> Well-Typed LLP, http://www.well-typed.com
>>
>> __

Beginners Digest, Vol 57, Issue 26

2013-03-18 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

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
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Simpler than lifting (Adrian May)
   2. Re:  Simpler than lifting (Brandon Allbery)
   3. Re:  Simpler than lifting (Brent Yorgey)
   4. Re:  Simpler than lifting (Daniel Trstenjak)
   5. Re:  Simpler than lifting (Adrian May)
   6.  newtype with a typclass (R?zvan Rotaru)
   7.  A good data structure for representing a tic-tac-toe board?
  (Costello, Roger L.)
   8. Re:  newtype with a typclass (Brandon Allbery)


--

Message: 1
Date: Mon, 18 Mar 2013 21:59:28 +0800
From: Adrian May 
Subject: [Haskell-beginners] Simpler than lifting
To: beginners@haskell.org
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hi All,

I have this in my code:

infixl 6 ~+, ~-
f ~+ g = \p -> f p + g p
f ~- g = \p -> f p - g p

but I feel that the prelude must have already taken care of such things.
What's the proper way to do it?

Thanks in advance,
Adrian.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130318/849bae5a/attachment-0001.htm>

--

Message: 2
Date: Mon, 18 Mar 2013 10:15:53 -0400
From: Brandon Allbery 
Subject: Re: [Haskell-beginners] Simpler than lifting
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Message-ID:

Content-Type: text/plain; charset="utf-8"

On Mon, Mar 18, 2013 at 9:59 AM, Adrian May
wrote:

> infixl 6 ~+, ~-
> f ~+ g = \p -> f p + g p
> f ~- g = \p -> f p - g p
>
> but I feel that the prelude must have already taken care of such things.
> What's the proper way to do it?
>

Not in the Prelude (which is specified by the Haskell Language Report and
difficult to change), but I think you want to look at Control.Applicative.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130318/0917a8c0/attachment-0001.htm>

--

Message: 3
Date: Mon, 18 Mar 2013 10:17:44 -0400
From: Brent Yorgey 
Subject: Re: [Haskell-beginners] Simpler than lifting
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Message-ID: <20130318141743.ga12...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Mon, Mar 18, 2013 at 10:15:53AM -0400, Brandon Allbery wrote:
> On Mon, Mar 18, 2013 at 9:59 AM, Adrian May
> wrote:
> 
> > infixl 6 ~+, ~-
> > f ~+ g = \p -> f p + g p
> > f ~- g = \p -> f p - g p
> >
> > but I feel that the prelude must have already taken care of such things.
> > What's the proper way to do it?
> >
> 
> Not in the Prelude (which is specified by the Haskell Language Report and
> difficult to change), but I think you want to look at
> Control.Applicative.

In particular, (~+) = liftA2 (+), and similarly for (~-).  This uses
the  ((->) e)  instance of Applicative.

-Brent



--

Message: 4
Date: Mon, 18 Mar 2013 16:23:13 +0100
From: Daniel Trstenjak 
Subject: Re: [Haskell-beginners] Simpler than lifting
To: beginners@haskell.org
Message-ID: <20130318152313.GA28800@machine>
Content-Type: text/plain; charset=us-ascii


> In particular, (~+) = liftA2 (+), and similarly for (~-).  This uses
> the  ((->) e)  instance of Applicative.

Or by using '<$>' and '<*>', which is a bit more general:

(+) <$> f <*> g

funcWith3Args <$> f <*> g <*> h


Greetings,
Daniel



--

Message: 5
Date: Mon, 18 Mar 2013 23:27:01 +0800
From: Adrian May 
Subject: Re: [Haskell-beginners] Simpler than lifting
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Message-ID:

Content-Type: text/plain; charset="utf-8"

Thanks everyone! I knew it would be in there somewhere but I wasn't sure
where to look. I'll play with that stuff in the morning.

Adri

Beginners Digest, Vol 57, Issue 27

2013-03-18 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

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
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  newtype with a typclass (R?zvan Rotaru)
   2. Re:  newtype with a typclass (Emmanuel Touzery)
   3. Re:  A good data structure for representing a tic-tac-toe
  board? (Peter Hall)
   4. Re:  A good data structure for representing a tic-tac-toe
  board? (Brent Yorgey)
   5. Re:  A good data structure for representing a tic-tac-toe
  board? (Lyndon Maydwell)


--

Message: 1
Date: Mon, 18 Mar 2013 20:10:19 +0200
From: R?zvan Rotaru 
Subject: Re: [Haskell-beginners] newtype with a typclass
To: beginners@haskell.org
Message-ID:

Content-Type: text/plain; charset="utf-8"

On 18 March 2013 18:34,  wrote:

>
> Not directly, no. It is possible to use existentials to do this ? at the
> cost that you lose the ability to do anything but what you have declared
> about it. For example, if you were to use this to make a map of Show-able
> values, the *only* thing you can do with the value is invoke "show" on it
> (in particular: you cannot pull out the value directly, because the only
> thing you know about it is that "show" works on it; you otherwise have no
> idea what it is!). And with such a value, referential transparency means
> there is no difference between this and storing the *result* of invoking
> "show" on it (that is, a String) instead, and laziness means that it may
> well actually store a thunk that will invoke "show" when the value is
> needed instead of computing and storing the value, so that there is in fact
> no difference between the two except that the type is much more complicated
> and both the type and the code are correspondingly more difficult to
> understand.
>
> What problem are you trying to solve by obfuscating things in this manner?
>
> Also note that most times when someone is trying to do this, they have
> confused typeclasses with OOP; they are not, and trying to treat them as
> such *will* lead you into dead ends.
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>

Well, I need something similar to Java interfaces. Or at least this is my
current way of thinking about the problem. I am trying to build some types
for GUI Widgets, and I would like to use Maps to keep their properties.
It's meant to replace the record syntax, which I find unusable because of
the name clash. I also would like to have fast non-destructive update of
this type, by using structural sharing, and Maps as good for this.

So, for example a Button would have an id, a label and function for the
onclick event, and these three values should be kept in a map, with the
keys "id", "label" and "onclick".

It's true that keeping Show-able values is not enough, since I won't be
able to call the onclick function. Unfortunately, I have no idea how to do
this as well.

Razvan
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130318/3da09c61/attachment-0001.htm>

--

Message: 2
Date: Mon, 18 Mar 2013 19:18:46 +0100
From: Emmanuel Touzery 
Subject: Re: [Haskell-beginners] newtype with a typclass
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Message-ID:

Content-Type: text/plain; charset="utf-8"

Maybe this article can interest you:
http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/

I think a record syntax is probably the best match, the biggest mismatch
between your approach and the haskell way might be the haskell preference
for immutability.

Maybe you should check how such things are implemented in existing gui
libraries in haskell.

emmanuel
On 18 Mar 2013 19:12, "R?zvan Rotaru"  wrote:

>
>
> On 18 March 2013 18:34,  wrote:
>
>>
>> Not directly, no. It is possible to use existentials to do this ? at the
>> cost that you lose the ability to do anything but what you have declared
>> about it. For example, if you were to use this to make a map of Show-able
>> values, the *only*