Re: [Haskell-beginners] Beginners Digest, Vol 53, Issue 7

Can anyone recommend a way of using Haskell on the web?
----- Original Message -----
From:
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-request@haskell.org
You can reach the person managing the list at beginners-owner@haskell.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..."
Today's Topics:
1. Double usage of a wire (arrow) (Nathan H?sken) 2. Trying to write netwire combiner similar to multicast (Nathan H?sken) 3. Re: Double usage of a wire (arrow) (Ertugrul S?ylemez) 4. Re: Trying to write netwire combiner similar to multicast (Ertugrul S?ylemez) 5. Re: Trying to write netwire combiner similar to multicast (Nathan H?sken) 6. Missing termination rule for recursive function (Oscar Benjamin) 7. Re: Missing termination rule for recursive function (Daniel Fischer) 8. Re: Missing termination rule for recursive function (Jay Sulzberger)
----------------------------------------------------------------------
Message: 1 Date: Mon, 05 Nov 2012 15:12:00 +0100 From: Nathan H?sken
Subject: [Haskell-beginners] Double usage of a wire (arrow) To: beginners@haskell.org Message-ID: <5097C930.605@posteo.de> Content-Type: text/plain; charset=ISO-8859-1 Hey,
If I double use an arrow (in this example a wire from netwire) like this:
objectWire :: WireP [Collision] Object objectWire = (Object <$> integral_ initPos) . speedWire <*> speedWire
will it be double evaluated, or can the compiler optimize this to evaluate speedWire only once?
Thanks! Nathan
------------------------------
Message: 2 Date: Mon, 05 Nov 2012 17:04:51 +0100 From: Nathan H?sken
Subject: [Haskell-beginners] Trying to write netwire combiner similar to multicast To: beginners@haskell.org Message-ID: <5097E3A3.5060208@posteo.de> Content-Type: text/plain; charset=ISO-8859-1 Hey,
I am trying to write a netwire combiner similar to multicast. The only difference is that when one of the wires inihibts, I want to remove it from the list.
So this is my attempt:
manager :: (Monad m) => [Wire e m a b] -> Wire e m [a] [b] manager ws' = mkGen $ \dt xs' -> do res <- mapM (\(w,x) -> stepWire w dt x) $ zip ws' xs' let filt (Left a, b) = Just (a, b) filt _ = Nothing resx = mapMaybe filt res return (Left $ (fmap fst) resx,manager (fmap snd resx))
ghc gives this compiler error:
BreakoutImproved.hs:90:62: Couldn't match type `e' with `[e]' `e' is a rigid type variable bound by the type signature for manager :: Monad m => [Wire e m a b] -> Wire e m [a] [b] at BreakoutImproved.hs:85:1 Expected type: [(e, Wire [e] m a b)] Actual type: [(e, Wire e m a b)] In the second argument of `fmap', namely `resx' In the first argument of `manager', namely `(fmap snd resx)'
Now this, I do not get. Why does manager expect an argument of type [(e, Wire [e] m a b)]. The type signature clearly says [(e, Wire e m a b)] (which is what it is getting).
Thanks! Nathan
------------------------------
Message: 3 Date: Mon, 5 Nov 2012 17:22:48 +0100 From: Ertugrul S?ylemez
Subject: Re: [Haskell-beginners] Double usage of a wire (arrow) To: beginners@haskell.org Message-ID: <20121105172248.11ea27da@tritium.streitmacht.eu> Content-Type: text/plain; charset="utf-8" Nathan H?sken
wrote: If I double use an arrow (in this example a wire from netwire) like this:
objectWire :: WireP [Collision] Object objectWire = (Object <$> integral_ initPos) . speedWire <*> speedWire
will it be double evaluated, or can the compiler optimize this to evaluate speedWire only once?
It will be double-evaluated. To prevent this you can use the Arrow interface:
proc x' -> do x <- speedWire -< x' {- ... use x ... -}
However, in WireP it's guaranteed that you get the same result, so for code conciseness you can still have speedWire twice, if sacrificing some speed is not too big an issue.
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.
participants (1)
-
Patrick Lynch