Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
> half-assed state for a real state solution, there's follow up here: http://groups.google.com/group/haskell-cafe/browse_thread/thread/d6143504c0e80075 2009/5/5 Thomas Hartman : >> interact (\s -> let (first,second) = span (not . null) (lines s) >               in unlines ("first":first++"second

using interact with state, was Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
Aha! There is in fact a way to fit this specification into the applicative paradigm. I'm a bit muzzy as to what it all means, but I must say, aesthetically I'm rather pleased with the result: module Main where import Control.Monad.State import Control.Applicative import Control.Applicative.Stat

Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
> interact (\s -> let (first,second) = span (not . null) (lines s) in unlines ("first":first++"second":takeWhile (not.null) second)) So, that didn't quite do the right thing, and it seemed like using span/break wouldn't scale well for more than two iterations. Here's another attempt

Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
seems to be the same behavior whether in ghci or compiled with ghc. 2009/5/5 Ketil Malde : > Thomas Hartman writes: > >> That's slick, but is there some way to use interact twice in the same >> program? > > No :-) > >> t10 = >>   let f = unlines . takeWhile (not . blank) . lines >>   in  do putS

Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Davie
I also tried t15 = let grabby = unlines . takeWhile (not . blank) . lines top = ("first time: " ++) . grabby . ("second time: " ++) . grabby in interact top but that didn't work either: thart...@ubuntu:~/haskell-learning/lazy-n-strict>runghc sequencing.hs a first time: second time:

Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Ketil Malde
Thomas Hartman writes: > That's slick, but is there some way to use interact twice in the same program? No :-) > t10 = > let f = unlines . takeWhile (not . blank) . lines > in do putStrLn "first time" > interact f > putStrLn "second time" > interact f > > this re

Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Hartman
That's slick, but is there some way to use interact twice in the same program? t10 = let f = unlines . takeWhile (not . blank) . lines in do putStrLn "first time" interact f putStrLn "second time" interact f this results in *** Exception: : hGetContents: illegal op

Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread Thomas Davie
On 4 May 2009, at 23:15, Thomas Hartman wrote: {-# LANGUAGE NoMonomorphismRestriction #-} import Data.List import Control.Monad import Control.Applicative -- Can the function below be tweaked to quit on blank input, provisioned in the applicative style? -- which function(s) needs to be rewritt

Re: [Haskell-cafe] applicative challenge

2009-05-05 Thread david48
On Mon, May 4, 2009 at 11:49 PM, Conor McBride wrote: > Remember folks: Missiles need miffy! Quote of the week ! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] applicative challenge

2009-05-04 Thread Felipe Lessa
On Mon, May 04, 2009 at 10:49:56PM +0100, Conor McBride wrote: > The effect of > > iffy askPresident launchMissiles seekUNResolution > > is to ask the President, then launch the missiles, then lobby the > UN, then decide that the result of seeking a UN resolution is > preferable. > > Remember fol

Re: [Haskell-cafe] applicative challenge

2009-05-04 Thread Tillmann Rendel
Thomas Hartman wrote: -- Can the function below be tweaked to quit on blank input, provisioned in the applicative style? No. Applicative on its own does not support to decide which action to take based on the result of some previous action. It is therefore not possible to look at the last lin

Re: [Haskell-cafe] applicative challenge

2009-05-04 Thread Conor McBride
Hi Thomas This is "iffy versus miffy", a standard applicative problem. When you use the result of one computation to choose the next computation (e.g., to decide whether you want to keep doing-and-taking), that's when you need yer actual monad. It's the join of a monad that lets you compute comp

[Haskell-cafe] applicative challenge

2009-05-04 Thread Thomas Hartman
{-# LANGUAGE NoMonomorphismRestriction #-} import Data.List import Control.Monad import Control.Applicative -- Can the function below be tweaked to quit on blank input, provisioned in the applicative style? -- which function(s) needs to be rewritten to make it so? -- Can you tell/guess which funct