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: Comfortable handling of module hierarchies (Karl Voelker) 2. FRP (Christopher Howard) 3. Re: FRP (Ertugrul S?ylemez) 4. Re: FRP (Ertugrul S?ylemez) 5. Re: FRP (Christopher Howard) 6. Re: FRP (Ertugrul S?ylemez) ---------------------------------------------------------------------- Message: 1 Date: Sat, 15 Sep 2012 09:00:55 -0700 From: Karl Voelker <ktvoel...@gmail.com> Subject: Re: [Haskell-beginners] Comfortable handling of module hierarchies To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <CAFfow0zM4QsP_3m_8Qx8JrCxa3-FXDzi89H4XoWXzP8uLs=m...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On Fri, Sep 14, 2012 at 6:23 PM, Christopher Howard <christopher.how...@frigidcode.com> wrote: > > import qualified Plant as P > > P.Fruit.Raspberry.jam Short answer: P.Fruit.Raspberry.jam would work if you said: import qualified Plant.Fruit.Raspberry as P.Fruit.Raspberry Long answer: You can't have exactly what you want because the Haskell module namespace isn't exactly heirarchical. Here's an excerpt from the Haskell 98 report [1]: "The name-space for modules themselves is flat, with each module being associated with a unique module name (which are Haskell identifiers beginning with a capital letter; i.e. modid)." Notice that this doesn't allow for dots in module names. A commonly-provided language extension allowed dots in module names, and compilers took these dots as a signal to look for a module's source at a particular place in the directory tree, but the semantics of the language didn't have a heirarchy of modules. Things haven't changed much in Haskell 2010, other than the existing use of dots being formalized [2]: "Module names can be thought of as being arranged in a hierarchy in which appending a new component creates a child of the original module name. For example, the module Control.Monad.ST is a child of the Control.Monad sub-hierarchy. This is purely a convention, however, and not part of the language definition; in this report a modid is treated as a single identifier occupying a flat namespace." In your code snippet, P.Fruit.Raspberry doesn't work because although P refers to the same module as Plant, there isn't anything "inside" P (or Plant) called Fruit.Raspberry. -Karl [1] http://www.haskell.org/onlinereport/modules.html [2] http://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-980005 ------------------------------ Message: 2 Date: Sat, 15 Sep 2012 22:15:04 -0800 From: Christopher Howard <christopher.how...@frigidcode.com> Subject: [Haskell-beginners] FRP To: Haskell Beginners <beginners@haskell.org> Message-ID: <50556e68.1000...@frigidcode.com> Content-Type: text/plain; charset="iso-8859-1" Hi. I'm trying to understand what Functional Reactive Programming is, or, more properly, what distinguishes it from "regular" functional programming, and what it would look like if I were to program in a "FRP Style", i.e., without some mysterious FRP module hiding the details. After reading a bunch of links and even looking at some source code I'm still not clear on this. If I program in an event-based style, and have data structures updating over time, with some data structures dependent on others for their values, and I use a functional language, is that FRP? Or is there some essential element I'm missing here? -- frigidcode.com indicium.us -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 551 bytes Desc: OpenPGP digital signature URL: <http://www.haskell.org/pipermail/beginners/attachments/20120915/944bf65e/attachment-0001.pgp> ------------------------------ Message: 3 Date: Sun, 16 Sep 2012 09:16:19 +0200 From: Ertugrul S?ylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] FRP To: beginners@haskell.org Message-ID: <20120916091619.44ace...@tritium.streitmacht.eu> Content-Type: text/plain; charset="us-ascii" Christopher Howard <christopher.how...@frigidcode.com> wrote: > Hi. I'm trying to understand what Functional Reactive Programming is, > or, more properly, what distinguishes it from "regular" functional > programming, and what it would look like if I were to program in a > "FRP Style", i.e., without some mysterious FRP module hiding the > details. After reading a bunch of links and even looking at some > source code I'm still not clear on this. > > If I program in an event-based style, and have data structures > updating over time, with some data structures dependent on others for > their values, and I use a functional language, is that FRP? Or is > there some essential element I'm missing here? Yes. FRP is about domain-specific languages that capture the notion of time-varying values. Let me take Netwire 4 as an example. It's not on Hackage yet, so you may want to grab it using darcs: darcs get http://darcs.ertes.de/netwire/ Imagine you have a simple GUI label that displays the number of seconds passed since program start. In an event-based model this is actually quite a complicated task. You would have to create a label and update it all the time using some form of timer/idle event. In Netwire you write: myLabel = time Now let's say you want to have the same GUI, but the time should start at 10 and pass twice as fast, so you actually want to display twice the number of seconds passed plus 10: myLabel = 10 + 2*time Imagine you want to display the string "yes" in a label: myLabel = "yes" Now let's say you want to display "yes", when the space key is held down and "no" otherwise: myLabel = "yes" . keyDown Space <|> "no" You want to display time while pressed and "Press space" while not: myLabel = fmap show time . keyDown Space <|> "no" You want to display "yes" every other second and "no" otherwise: myLabel = "yes" . holdFor 1 (periodically 2) <|> "no" Imagine doing that with event-based code. Summary: FRP is about handling time-varying values like they were regular values. Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120916/522c5fb1/attachment-0001.pgp> ------------------------------ Message: 4 Date: Sun, 16 Sep 2012 09:20:55 +0200 From: Ertugrul S?ylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] FRP To: beginners@haskell.org Message-ID: <20120916092055.3f524...@tritium.streitmacht.eu> Content-Type: text/plain; charset="utf-8" Ertugrul S?ylemez <e...@ertes.de> wrote: > You want to display time while pressed and "Press space" while not: > > myLabel = fmap show time . keyDown Space <|> "no" Typo: myLabel = fmap show time . keyDown Space <|> "Press space" Of course. =) Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120916/636b78e0/attachment-0001.pgp> ------------------------------ Message: 5 Date: Sun, 16 Sep 2012 00:34:21 -0800 From: Christopher Howard <christopher.how...@frigidcode.com> Subject: Re: [Haskell-beginners] FRP To: Haskell Beginners <beginners@haskell.org> Message-ID: <50558f0d.3010...@frigidcode.com> Content-Type: text/plain; charset="iso-8859-1" On 09/15/2012 11:16 PM, Ertugrul S?ylemez wrote: > > Summary: FRP is about handling time-varying values like they were > regular values. > Ouch!... Ouch!... My head is beginning to explode! So, I think I understand the main idea you just explained, but now I am curious about how this black magic is possible. Presumably, these mystical "time-varying values" would actually have to be some kind of partially applied function that receives a time parameter. But how do we, as in your example, add a literal number to a function? -- frigidcode.com indicium.us -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 551 bytes Desc: OpenPGP digital signature URL: <http://www.haskell.org/pipermail/beginners/attachments/20120916/246b53d1/attachment-0001.pgp> ------------------------------ Message: 6 Date: Sun, 16 Sep 2012 10:37:15 +0200 From: Ertugrul S?ylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] FRP To: beginners@haskell.org Message-ID: <20120916103715.081e8...@tritium.streitmacht.eu> Content-Type: text/plain; charset="us-ascii" Christopher Howard <christopher.how...@frigidcode.com> wrote: > > Summary: FRP is about handling time-varying values like they were > > regular values. > > Ouch!... Ouch!... My head is beginning to explode! > > So, I think I understand the main idea you just explained, but now I > am curious about how this black magic is possible. Presumably, these > mystical "time-varying values" would actually have to be some kind of > partially applied function that receives a time parameter. But how do > we, as in your example, add a literal number to a function? One very simple and naive way to implement FRP is this: newtype Behavior a = Behavior (Time -> a) 'Behavior' is the traditional name for a time-varying value. Then a constant is, as the name says, a constant: instance Applicative Behavior where pure = Behavior . const {- ... -} To get the notation I have used you just need Haskell's fromInteger magic: instance (Num a) => Num (Behavior a) where (+) = liftA2 (+) (-) = liftA2 (-) {- ... -} fromInteger = pure . fromInteger Given that and a behavior that returns the current time, time :: Behavior Time time = Behavior id you can now have 10 + 2*time Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120916/32c12aa2/attachment-0001.pgp> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 51, Issue 23 *****************************************