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. self recursive lambda (sarfraz) 2. netwire and "dynamic" list of objects (Nathan H?sken) 3. Re: self recursive lambda (Antoine Latter) 4. Re: self recursive lambda (sarfraz) ---------------------------------------------------------------------- Message: 1 Date: Mon, 9 Apr 2012 17:57:22 +0200 From: sarfraz <dragoon.emp...@yahoo.fr> Subject: [Haskell-beginners] self recursive lambda To: beginners@haskell.org Message-ID: <20120409155722.GA673@unvrs> Content-Type: text/plain; charset="us-ascii" Hi, Can't seem to be able to debug the following: import System.IO nHead :: Int -> String -> String nHead n str = if (length str) < n then str else if n ==0 then str else (\x n str -> if n == 0 -- this lambda does not work then str else x (n - 1) (tail str)) main = interact (nHead 5) I see where the problem is. But surely it is possible to make a recursive lambda. (I want to use a lambda, i know how to do otherwise) -- Sarfraz K. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 490 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120409/88ed1b2b/attachment-0001.pgp> ------------------------------ Message: 2 Date: Mon, 09 Apr 2012 18:40:52 +0200 From: Nathan H?sken <nathan.hues...@posteo.de> Subject: [Haskell-beginners] netwire and "dynamic" list of objects To: beginners@haskell.org Message-ID: <4f831114.4090...@posteo.de> Content-Type: text/plain; charset=ISO-8859-1 Hey, I have a simple SDL based graphic demo, which I am trying (for educational purposes) to rewrite utilizing netwire. The demo basically consists of a State which contains a list of object states. data ObjectState = ... data State = State [ObjectState] Then there is a function updateState which updates all objects, removing some and adding some new ones. updateState :: State -> State updateState (State oss) = State (catMaybes $ map updateObject $ newObjects ++ oss) where updateObject :: ObjectState -> Maybe ObjectState updateObject = ... newObjects :: [ObjectState] newObjects = ... OK, now I wrote a wire: type MyWire = Wire.Wire () (Kleisli IO) wire :: GameState -> MyWire () GameState wire initGS = proc _ -> do rec gs' <- Wire.delay initGS -< gs gs <- arr updateState -< gs' returnA -< gs Works wonderfully :). But I avoided rewriting "updateState" in wire format. But I have no Idea how to do that. How do I handle a dynamic list of objects in a wire? Thanks! Nathan ------------------------------ Message: 3 Date: Mon, 9 Apr 2012 12:28:42 -0500 From: Antoine Latter <aslat...@gmail.com> Subject: Re: [Haskell-beginners] self recursive lambda To: beginners@haskell.org Message-ID: <CAKjSnQHdqvxjy8srRyC3q5BzWftVM2f=R1Y9FZAV4m0m6ZS=s...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Mon, Apr 9, 2012 at 10:57 AM, sarfraz <dragoon.emp...@yahoo.fr> wrote: > Hi, > > Can't seem to be able to debug the following: > > import System.IO > > nHead :: Int -> String -> String > nHead n str = if (length str) < n > ? ? ? ? ? ? ?then str > ? ? ? ? ? ? ?else if n ==0 > ? ? ? ? ? ? ? ? ? then str > ? ? ? ? ? ? ? ? ? else (\x n str -> if n == 0 > -- this lambda does not work > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? then str > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else x (n - 1) (tail str)) > > main = interact (nHead 5) > > I see where the problem is. But surely it is possible to make a > recursive lambda. (I want to use a lambda, i know how to do otherwise) You can't make a recursive lambda directly - you need a helper function: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Function.html#v:fix Example usage: > let factNonResursive = \fact n -> if n < 2 then 1 else n * fact (n - 1) > fix factNonRecursive 5 Antoine ------------------------------ Message: 4 Date: Mon, 9 Apr 2012 20:13:48 +0200 From: sarfraz <dragoon.emp...@yahoo.fr> Subject: Re: [Haskell-beginners] self recursive lambda To: beginners@haskell.org Message-ID: <20120409181347.GA619@unvrs> Content-Type: text/plain; charset="iso-8859-1" Ok thanks, got it working: import System.IO import Control.Monad.Fix nHead :: Int -> String -> String nHead n str = let rec = \x n str -> if n == 0 then str else x (n - 1) (tail str) in if (length str) < n then str else fix rec n str main = interact (nHead 5) In the end I will be using: import System.IO nHead :: Int -> String -> String nHead n str = let rec n str = if n == 0 then str else x (n - 1) (tail str) in if (length str) < n then str else rec n str main = interact (nHead 5) But it's good to know that it was possible. On Mon, Apr 09, 2012 at 12:28:42PM -0500, Antoine Latter wrote: > On Mon, Apr 9, 2012 at 10:57 AM, sarfraz <dragoon.emp...@yahoo.fr> wrote: > > Hi, > > > > Can't seem to be able to debug the following: > > > > import System.IO > > > > nHead :: Int -> String -> String > > nHead n str = if (length str) < n > > ? ? ? ? ? ? ?then str > > ? ? ? ? ? ? ?else if n ==0 > > ? ? ? ? ? ? ? ? ? then str > > ? ? ? ? ? ? ? ? ? else (\x n str -> if n == 0 > > -- this lambda does not work > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? then str > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else x (n - 1) (tail str)) > > > > main = interact (nHead 5) > > > > I see where the problem is. But surely it is possible to make a > > recursive lambda. (I want to use a lambda, i know how to do otherwise) > > You can't make a recursive lambda directly - you need a helper function: > > http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Function.html#v:fix > > Example usage: > > > let factNonResursive = \fact n -> if n < 2 then 1 else n * fact (n - 1) > > fix factNonRecursive 5 > > Antoine > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners -- Sarfraz K. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 490 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120409/cce5c9c6/attachment-0001.pgp> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 46, Issue 11 *****************************************