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:  Strange new Haskell Platform (Lorenzo Bolla)
   2. Re:  Strange new Haskell Platform (bucephalus org)
   3. Re:  an observation about Haskell vs. Python (Dennis Raddle)
   4.  elegant handling of maybe and non-maybe values
      (Christopher Howard)
   5. Re:  FRP (Ertugrul S?ylemez)
   6. Re:  elegant handling of maybe and non-maybe      values (Kyle Murphy)


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

Message: 1
Date: Thu, 20 Sep 2012 14:37:35 +0100
From: Lorenzo Bolla <[email protected]>
Subject: Re: [Haskell-beginners] Strange new Haskell Platform
To: bucephalus org <[email protected]>
Cc: [email protected]
Message-ID:
        <cadjgtrwvhoqt87krde-razkshzrxsap-dphtea2mbj9vtw3...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

You probably want `System.Process.system`:
http://hackage.haskell.org/packages/archive/process/latest/doc/html/System-Process.html#v:system

L.


On Thu, Sep 20, 2012 at 2:29 PM, bucephalus org
<[email protected]> wrote:
> Dear Corentin, Dear Chaddai, Dear Lorenzo,
>
> Thank you for your replies, they explain everything I didn't understand.
>
> Only, I cannot find the new equivalent for the old
>   System.system
> function, which doesn't appear anymore? At least not in
> http://www.haskell.org/ghc/docs/7.4-latest/html/libraries/base-4.5.1.0/doc-index-S.htm
> ?
>
> Actually, I always use it in a little helper file I apply in all my Haskell
> projects. For example, if a project has modules M1.hs and M2.hs, this helper
> file is
>      -- helper.hs
>      import System
>      import M1
>      import M2
>      myhaddock = System.system "haddock -h M1.hs M2.hs"
> so that I can start each session simply with
>     $ ghci
>     Prelude> :l helper.hs
> and I can generate the docs M1.html and M2.html for my project simply with
>     Main> myhaddock
>
> I could probably do all this with some built-in tools. For example there is
>   Distribution.Simple.Haddock.haddock :: PackageDescription ->
> LocalBuildInfo -> [PPSuffixHandler] -> IO ()
> but all this might be well programmed, but is so poorly documented, that I
> am not able figure that out.
>
> A while ago I did an intensive study on this whole Cabal, and at that stage
> I became really frustrated with Haskell. I had spent a lot of time in
> realizing two nice projects, but I was not able to cabalize and publish
> them. Since then, I am just waiting and hoping for a thorough introduction
> (beyond the overwhelming Cabal manual) that explains all that to mere
> mortals.
>
> Anyway, thank you very much again.
> Regards, Tom
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

Message: 2
Date: Thu, 20 Sep 2012 15:40:29 +0200
From: bucephalus org <[email protected]>
Subject: Re: [Haskell-beginners] Strange new Haskell Platform
To: Lorenzo Bolla <[email protected]>
Cc: [email protected]
Message-ID:
        <CAJ6-dtqzh+ik-4t+XXYAEQ3e784XpS31=2bwbxbrue7zgn+...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi Brent, Hi Lorenzo,
Wow! Indeed, there it is.
Thank you!!

On Thu, Sep 20, 2012 at 3:37 PM, Lorenzo Bolla <[email protected]> wrote:

> You probably want `System.Process.system`:
>
> http://hackage.haskell.org/packages/archive/process/latest/doc/html/System-Process.html#v:system
>
> L.
>
>
> On Thu, Sep 20, 2012 at 2:29 PM, bucephalus org
> <[email protected]> wrote:
> > Dear Corentin, Dear Chaddai, Dear Lorenzo,
> >
> > Thank you for your replies, they explain everything I didn't understand.
> >
> > Only, I cannot find the new equivalent for the old
> >   System.system
> > function, which doesn't appear anymore? At least not in
> >
> http://www.haskell.org/ghc/docs/7.4-latest/html/libraries/base-4.5.1.0/doc-index-S.htm
> > ?
> >
> > Actually, I always use it in a little helper file I apply in all my
> Haskell
> > projects. For example, if a project has modules M1.hs and M2.hs, this
> helper
> > file is
> >      -- helper.hs
> >      import System
> >      import M1
> >      import M2
> >      myhaddock = System.system "haddock -h M1.hs M2.hs"
> > so that I can start each session simply with
> >     $ ghci
> >     Prelude> :l helper.hs
> > and I can generate the docs M1.html and M2.html for my project simply
> with
> >     Main> myhaddock
> >
> > I could probably do all this with some built-in tools. For example there
> is
> >   Distribution.Simple.Haddock.haddock :: PackageDescription ->
> > LocalBuildInfo -> [PPSuffixHandler] -> IO ()
> > but all this might be well programmed, but is so poorly documented, that
> I
> > am not able figure that out.
> >
> > A while ago I did an intensive study on this whole Cabal, and at that
> stage
> > I became really frustrated with Haskell. I had spent a lot of time in
> > realizing two nice projects, but I was not able to cabalize and publish
> > them. Since then, I am just waiting and hoping for a thorough
> introduction
> > (beyond the overwhelming Cabal manual) that explains all that to mere
> > mortals.
> >
> > Anyway, thank you very much again.
> > Regards, Tom
> >
> > _______________________________________________
> > 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/20120920/a43131a5/attachment-0001.htm>

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

Message: 3
Date: Thu, 20 Sep 2012 08:08:03 -0700
From: Dennis Raddle <[email protected]>
Subject: Re: [Haskell-beginners] an observation about Haskell vs.
        Python
To: David Hinkes <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <cakxlvoojg70saek_7w1sbo9e2nbbsqu5t9an3efajzjg6bf...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

This kind of thing is hard to prove or even explain, but I feel that
Haskell error messages tend to point me to the cognitive mistakes, the ways
I'm thinking wrongly about the problem. Whereas scripting language errors
just point me to superficial brain farts. By the time I get Haskell code to
compile, I already understand that code an order of magnitude deeper. That
makes haskell VALUABLE. (to me)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120920/6c026b53/attachment-0001.htm>

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

Message: 4
Date: Thu, 20 Sep 2012 17:25:03 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] elegant handling of maybe and non-maybe
        values
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I have a code situation similar to this simplified one: Let's say that
I've got a value v that is a Maybe type, and values x, y, and z that are
not. x, y, and z are dependent on the value inside v. So I must provide
default values for x, y, and z. An additional complication is that every
calculation returns a new (possibly different) value for v. So, I could
do something like this:

code:
--------
let (v', x) = case v of
                Nothing -> (Nothing, defaultValueOfX)
                Just vValue -> f vValue in
let (v'', y) = case v' of
                 Nothing -> (Nothing, defaultValueOfY)
                 Just vValue -> g vValue in
let (v''', z) = case v'' of
                  Nothing -> (Nothing, defaultValueOfZ)
                  Just vValue -> h vValue in
--------

(f, g, h represent the calculations I am performing.) In the end, I need
the values of x, y, and z, and the last v value.

Obviously, the above solution is not very elegant, especially if I add a
few more variables. My other thought was some kind of fold operation,
where I store the functions (calculations) and the default values in a
list, and then fold over the list, applying subsequent values of v or
returning default values, as appropriate. But this seems rather clunky,
especially if I want to attach the values in the new list to variable
names afterwards.

Is there a better approach?

-- 
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/20120920/fa1586e7/attachment-0001.pgp>

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

Message: 5
Date: Fri, 21 Sep 2012 03:53:28 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] FRP
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Heinrich Apfelmus <[email protected]> wrote:

> > Wire is also an Alternative, which allows concise and efficient
> > switching with very little cruft.  The following wire renders "yes"
> > when the "keyDown Space" event happens and "no" otherwise:
> >
> >     pure "yes" . keyDown Space <|> pure "no"
> >
> > Or with the OverloadedStrings extension:
> >
> >     "yes" . keyDown Space <|> "no"
> >
> > All classic (non-wire) FRP implementations need switching or another
> > ad-hoc combinator for this.  If you happen to need switching it's
> > also a lot simpler using wires:
> >
> >     "please press space" . notE (keyDown Space) --> "thanks"
> >
> > This one waits for the Space key and then outputs "thanks" forever.
> > So far Netwire has the fastest and most elegant way of dealing with
> > events compared to all other libraries I have tried.
>
> These examples look neat!
>
> I'm a bit confused about the model you are using, though. If I
> understand that correctly, you don't distinguish between events and
> behaviors; rather, you are working with data streams in discrete time
> steps. Still, I don't quite understand.

First let me try to put reactive-banana's model into a data type of my
own, which you might call TimedZipStream.  The name Behavior is easier,
so let me pick that one instead (Time is the type for time deltas):

    newtype Behavior a =
        Behavior {
          stepBehavior :: Time -> Network (a, Behavior a)
        }

This is not anywhere near how reactive-banana represents its behaviors,
but just a simplified and less powerful model.  The argument is the time
delta to the last instant.  Communication happens through the Network
monad and is opaque to the user.  The type is an applicative functor
that represents values that can behave differently at each instant.

My model is similar to Yampas model, where instead of time-varying
values you have time-varying functions, so-called signal functions:

    newtype SF a b =
        SF {
          stepSF :: Time -> a -> (b, SF a b)
        }

This is a function from an 'a' to a 'b' that mutates over time.  There
is a counterpart for classic behaviors, which is when the input type is
fully polymorphic:

    time :: SF a Time

SF forms a family of applicative functors, but now there is a direct
path from one signal function to the next, because SF is itself a
category.  No graph, no monad, just plain categorical composition.
Unfortunately to this day Yampa does not provide an Applicative
instance, so you have to use the Arrow interface, which is usually very
ugly.

The weak spot of both models is events.  They need to be handled using
switchers and other combinators.  Causality, simultaneity and choice all
need to be encoded explicitly.  Event modifiers work outside of the
behavior level.

What makes Netwire different?  Wire categories are encoded by the
following (simplified) type:

    newtype Wire e a b =
        Wire {
          stepWire :: Time -> a -> (Either e b, Wire e a b)
        }

Wires can choose not to output anything, but instead inhibit with a
value of type 'e'.  Where i is an inhibiting wire the following
identities hold:

    x . i = i
    i . x = i

Furthermore now when 'e' is a Monoid Wire is a family of Alternative
functors with the following identities, where x and y produce and i, j
and ij' and inhibit:

    x <|> y = x
    i <|> y = y

    i <|> j = ij'

The ij' wire also inhibits, but mappend-combines the inhibition values.
The empty wire always inhibits with mempty.  The monoid is necessary for
the Category, Applicative and Alternative laws to hold.


> What is
>
>      pure "yes" . keyDown Space <|> pure "no"
>
> supposed to mean? If it's a function Time -> String , how long does it
> have the "yes" value? 439.7 milliseconds? If it's an event, how often
> does the "no" event fire?

An event wire is a wire that acts like the identity wire when it
produces, but may choose to inhibit instead:

    pure "yes" . keyDown Space

The 'keyDown Space' wire acts like the identity wire when the space key
is pressed, otherwise it inhibits.  As a consequence of the above laws
the composition also inhibits.  This is where (<|>) comes in:

    pure "yes" . keyDown Space <|> pure "no"

When the left wire inhibits, the right wire takes over.  By definition a
'pure' wire never inhibits.  Notice that in this example I'm assuming
that 'keyDown' is a 'continuous event'.  That's where behaviors are
mixed with events.  An event can actually have a duration.

If 'keyDown' would be instantaneous without a duration you could use the
'holdFor' combinator:

    pure "yes" . holdFor 1 (keyDown Space) <|> pure "no"

This would also work for a continuous 'keyDown' event wire.  Then if you
press the space key for one second, "yes" is displayed for two seconds.


> Concerning the other example, I don't understand what the expression
>
>     "please press space" . notE (keyDown Space)
>
> means. If it's a function, what value does it have when the key was
> pressed? If it's an event, how often does it "fire" the string value?

In this case it doesn't really matter if 'keyDown Space' has a duration
or not.  As soon as it produces once, the switch happens and the next
wire takes over.  There is another name for the (-->) combinator called
'andThen'.

    x --> y

As soon as x inhibits, this combination switches to y.

Side note:  Unlike classic FRP a wire category is not time-bound.  In
fact in the current official release of Netwire (3.1.0) time is actually
an extension.  In Netwire time is back as a primitive, because it makes
time-related wires (the analog to behaviors) much easier to write.  I
have retained the flexibility that your wire can have a time frame
different from real time, though.


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/20120921/6291fc2a/attachment-0001.pgp>

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

Message: 6
Date: Thu, 20 Sep 2012 23:18:18 -0400
From: Kyle Murphy <[email protected]>
Subject: Re: [Haskell-beginners] elegant handling of maybe and
        non-maybe       values
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <CA+y6JcxZRskZwybNy8ueddfBDYiHYKcYy7W=ojscporupwo...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

I don't know if it's better, but there are a couple things that stick out to me.
First of all this:

--------
let (v', x) = case v of
                Nothing -> (Nothing, defaultValueOfX)
                Just vValue -> f vValue in
--------

Is encapsulated in the function maybe as in:

--------
let (v,' x) = maybe (Nothing, defaultValueOfX) f v
--------

I'm assuming in this case that v has type (Maybe a) and is the original input.
This sort of computation puts me in mind of the State monad though,
and I think the best solution
is going to involve it, or possibly Arrow.

-------
wrapWithState :: (a -> (Maybe a, b)) -> b -> State (Maybe a) b
wrapWithState f default = do
                                     v <- get
                                     let (v', x) = maybe (Nothing, default) f v
                                     put v'
                                     return x

x :: State (Maybe a) b
x = wrapWithState f defaultValueOfX
y :: State (Maybe a) b
y = wrapWithState g defaultValueOfY
z :: State (Maybe a) b
z = wrapWithState h defaultValueOfZ

getXYZ :: State (Maybe a) b
getXYZ = do
    x' <- x
    y' <- y
    z' <- z
    doSomethingWithXYZ x' y' z'

getV :: IO (a, v)
getV = do
   v <- whateverToGetV
   return $ runState getXYZ v
-------

That's really long and probably somewhat convoluted, plus I'd bet
there's a more elegant way
to do it with Applicative/Functor/Arrow, but I believe it should work.
Note that I use "b" as
the return type for all the state computations, but in practice they
could all return different types.

-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.


On Thu, Sep 20, 2012 at 9:25 PM, Christopher Howard
<[email protected]> wrote:
>
> I have a code situation similar to this simplified one: Let's say that
> I've got a value v that is a Maybe type, and values x, y, and z that are
> not. x, y, and z are dependent on the value inside v. So I must provide
> default values for x, y, and z. An additional complication is that every
> calculation returns a new (possibly different) value for v. So, I could
> do something like this:
>
> code:
> --------
> let (v', x) = case v of
>                 Nothing -> (Nothing, defaultValueOfX)
>                 Just vValue -> f vValue in
> let (v'', y) = case v' of
>                  Nothing -> (Nothing, defaultValueOfY)
>                  Just vValue -> g vValue in
> let (v''', z) = case v'' of
>                   Nothing -> (Nothing, defaultValueOfZ)
>                   Just vValue -> h vValue in
> --------
>
> (f, g, h represent the calculations I am performing.) In the end, I need
> the values of x, y, and z, and the last v value.
>
> Obviously, the above solution is not very elegant, especially if I add a
> few more variables. My other thought was some kind of fold operation,
> where I store the functions (calculations) and the default values in a
> list, and then fold over the list, applying subsequent values of v or
> returning default values, as appropriate. But this seems rather clunky,
> especially if I want to attach the values in the new list to variable
> names afterwards.
>
> Is there a better approach?
>
> --
> frigidcode.com
> indicium.us
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

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


End of Beginners Digest, Vol 51, Issue 33
*****************************************

Reply via email to