Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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:  Mutable collection of gui objects    (wxHaskell) (Jeffrey Brown)
   2. Re:  Mutable collection of gui objects    (wxHaskell)
      (Henk-Jan van Tuyl)
   3. Re:  Mutable collection of gui objects    (wxHaskell)
      (emacstheviking)


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

Message: 1
Date: Tue, 31 Mar 2015 13:11:47 -0700
From: Jeffrey Brown <[email protected]>
To: Henk-Jan van Tuyl <[email protected]>
Cc: The Haskell-Beginners Mailing List <[email protected]>
Subject: Re: [Haskell-beginners] Mutable collection of gui objects
        (wxHaskell)
Message-ID:
        <caec4ma2ccaafcc9eynja7a3rnlchdf74kc30tflud4aaheo...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

It works! And I don't understand it! Particularly this line:

  inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar

I'm considering the type signatures:
  map :: (a -> b) -> [a] -> [b]
  (<$>) :: Functor f => (a -> b) -> f a -> f b
  varGet :: Var a -> IO a
map and <$> (fmap) are nearly synonymous; map seems like a special case of
fmap. I gather the fmap must be to map inside the IO type that varGet
returns, and the map must be mapping across some list. But what about their
function arguments? Is map using the lambda expression, or is fmap? What
function argument is the other one using? Are they both somehow sharing the
lambda expression?

On Tue, Mar 31, 2015 at 12:48 AM, Henk-Jan van Tuyl <[email protected]>
wrote:

> On Tue, 31 Mar 2015 04:14:35 +0200, Jeffrey Brown <[email protected]>
> wrote:
>
> :
>
>> I am trying to modify Layout.hs [1] to permit a variable number, rather
>> than a fixed number, of text entry boxes. I shrank the program, mostly by
>> removing features, until it was this:
>>
>>   main = start $ do
>>     f      <- frame  [text := "Layout test"]
>>     p      <- panel  f []
>>     xinput <- textEntry p [text := "100"]
>>     yinput <- textEntry p [text := "100"]
>>     myVar <- varCreate [xinput,yinput]
>>     set f [ layout := container p $ margin 10 $
>>       column 5 [boxed "coordinates" (grid 5 5
>>           [[hfill $ widget xinput], [hfill $ widget yinput]] -- replacing
>>         ) ] ]
>>     return ()
>>
>> I want to replace the line marked "replacing". Rather than hard-coding the
>> number of text entry boxes (2), I want it to deal with a mutable
>> collection
>> of them, in myVar.
>>
>> I tried this:
>>   [ fmap (\e -> hfill $ widget e) $ varGet myVar ]
>>
> :
>
> The result of varGet is of type "IO something", you must convert that to
> "something", by using "<-". You can do this by adding the line:
>   inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar
> before the set command (note the square brackets). The <$> operator is
> from module Data.Functor and is defined as
>   (<$>) = fmap
>
> The main function becomes this:
>   main = start $ do
>       f      <- frame  [text := "Layout test"]
>       p      <- panel  f []
>       xinput <- textEntry p [text := "100"]
>       yinput <- textEntry p [text := "100"]
>       myVar  <- varCreate [xinput, yinput]
>       inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar
>       set f [ layout := container p $ margin 10 $
>               column 5 [boxed "coordinates" (grid 5 5 inputs)]
>             ]
>       return ()
>
>
> Regards,
> Henk-Jan van Tuyl
>
>
> --
> 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
> Haskell programming
> --
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150331/5bb46d7f/attachment-0001.html>

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

Message: 2
Date: Wed, 01 Apr 2015 00:51:44 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
To: "Jeffrey Brown" <[email protected]>
Cc: The Haskell-Beginners Mailing List <[email protected]>
Subject: Re: [Haskell-beginners] Mutable collection of gui objects
        (wxHaskell)
Message-ID: <op.xwdwgiw7pz0j5l@alquantor>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
        delsp=yes

On Tue, 31 Mar 2015 22:11:47 +0200, Jeffrey Brown  
<[email protected]> wrote:

> It works! And I don't understand it! Particularly this line:
>
>   inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar
>
> I'm considering the type signatures:
>   map :: (a -> b) -> [a] -> [b]
>   (<$>) :: Functor f => (a -> b) -> f a -> f b
>   varGet :: Var a -> IO a
> map and <$> (fmap) are nearly synonymous; map seems like a special case  
> of
> fmap. I gather the fmap must be to map inside the IO type that varGet
> returns, and the map must be mapping across some list. But what about  
> their
> function arguments? Is map using the lambda expression, or is fmap? What
> function argument is the other one using? Are they both somehow sharing  
> the
> lambda expression?

The expression
   f <$> x
is equal to
   fmap f x
. If
   f :: a -> b
   x :: IO a
then
   fmap f :: IO a -> IO b
. You could say, fmap lifts f to the IO monad (you could also use liftM  
for this).

In your case, f is
   map (\e -> [hfill $ widget e])
and x is
   varGet myVar
You stored a list of textEntrys in myVar, the lambda expression is mapped  
over this list.

Another way to look at it: you can replace the line
   inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar
with
   xs <- varGet myVar
   let inputs = map (\e -> [hfill $ widget e]) xs

Regards,
Henk-Jan van Tuyl


-- 
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
Haskell programming
--


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

Message: 3
Date: Wed, 1 Apr 2015 09:44:30 +0100
From: emacstheviking <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Mutable collection of gui objects
        (wxHaskell)
Message-ID:
        <CAEiEuU+CKSS5eUzk=qrwgkcogfnvfi-hekghxpstlgssws-...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

No wonder Haskell won't catch on... I saw code that looked just like that
on the wall of a pyramid on an episode Ancient Aliens recently!

April fool by the way!



On 31 March 2015 at 23:51, Henk-Jan van Tuyl <[email protected]> wrote:

> On Tue, 31 Mar 2015 22:11:47 +0200, Jeffrey Brown <[email protected]>
> wrote:
>
>  It works! And I don't understand it! Particularly this line:
>>
>>   inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar
>>
>> I'm considering the type signatures:
>>   map :: (a -> b) -> [a] -> [b]
>>   (<$>) :: Functor f => (a -> b) -> f a -> f b
>>   varGet :: Var a -> IO a
>> map and <$> (fmap) are nearly synonymous; map seems like a special case of
>> fmap. I gather the fmap must be to map inside the IO type that varGet
>> returns, and the map must be mapping across some list. But what about
>> their
>> function arguments? Is map using the lambda expression, or is fmap? What
>> function argument is the other one using? Are they both somehow sharing
>> the
>> lambda expression?
>>
>
> The expression
>   f <$> x
> is equal to
>   fmap f x
> . If
>   f :: a -> b
>   x :: IO a
> then
>   fmap f :: IO a -> IO b
> . You could say, fmap lifts f to the IO monad (you could also use liftM
> for this).
>
> In your case, f is
>   map (\e -> [hfill $ widget e])
> and x is
>   varGet myVar
> You stored a list of textEntrys in myVar, the lambda expression is mapped
> over this list.
>
> Another way to look at it: you can replace the line
>   inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar
> with
>   xs <- varGet myVar
>   let inputs = map (\e -> [hfill $ widget e]) xs
>
> Regards,
> Henk-Jan van Tuyl
>
>
> --
> 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
> Haskell programming
> --
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150401/23ee429f/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 82, Issue 1
****************************************

Reply via email to