> 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
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
> 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
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
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:
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
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
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
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
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
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
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
{-# 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
13 matches
Mail list logo