#apache #archlinux #asterisk #centos #debian #gentoo #haskell #kde #kubuntu #lisp #math #mysql #perl #python #ruby-lang #rubyonrails #suse #ubuntu #vim #wikipedia 0 1 2 3 4 5 6 7 8 9
Top Prev 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 Next
#haskell
<nmessenger> first takes a function (a -> b) and applies it the the fst of a pair ((a,t) -> (b,t))
<nmessenger> (well actually it takes an Arrow t a b, but (->) is an easy and familiar Arrow)
<nmessenger> > (first . (:)) 1 ([2,3], 4)
<lambdabot> ([1,2,3],4)
<dons> ?uptime
<lambdabot> uptime: 2d 10h 3m 32s, longest uptime: 2d 17h 27m 21s
<dons> ?users
<lambdabot> Maximum users seen in #haskell: 316, currently: 281 (88.9%), active: 35 (12.5%)
<EvilTerran> is there a canonical translation of list comprehensions into maps?
<dcoutts> EvilTerran, yep, in the H98 report
<dcoutts> and it's not map, it's concatMap
<nmessenger> @where report
<lambdabot> http://www.haskell.org/onlinereport/
<EvilTerran> [f x | x <- xs] is clearly map f xs, but i'm having trouble figuring out with multiple <-s
<EvilTerran> ah, ok
<nmessenger> http://www.haskell.org/onlinereport/exps.html#sect3.11
<lambdabot> Title: The Haskell 98 Report: Expressions
<dcoutts> EvilTerran, I've got a simple implementation of the transformation somewhere
<dcoutts> but you can do it by hand easily by following the rules in the report
<EvilTerran> thanks
<xerox> EvilTerran: cartesian product.
<xerox> > let xs = [1..3] in liftM3 (,,) xs xs xs -- [(x,y,z) | x <- xs, y <- xs, z <- xs]
<lambdabot> [(1,1,1),(1,1,2),(1,1,3),(1,2,1),(1,2,2),(1,2,3),(1,3,1),(1,3,2),(1,3,3),(2,...
<EvilTerran> I just realised that my horrible O(...) wasn't actually that bad, because i had a [...| x <- xs, y <- ys], with ys not dependent on x (so presumably only evaluated once)
<EvilTerran> and that's equivalent to [...| (x,y) <- cartProd xs ys] in that case
<EvilTerran> > (,) `ap` [1,2] `ap` [3,4]
<lambdabot> Couldn't match expected type `a -> b'
<EvilTerran> ?ty ap
<lambdabot> forall (m :: * -> *) a b. (Monad m) => m (a -> b) -> m a -> m b
<xerox> > return (,) `ap` [1,2] `ap` [3,4]
<lambdabot> [(1,3),(1,4),(2,3),(2,4)]
<EvilTerran> ahh
<nmessenger> > (,) `fmap` [1,2] `ap` [3,4]
<lambdabot> [(1,3),(1,4),(2,3),(2,4)]
<EvilTerran> even better
<nmessenger> > liftM2 (,) [1,2] [3,4] -- :P
<lambdabot> [(1,3),(1,4),(2,3),(2,4)]
<nmessenger> heh
<Botje> be lglad it's not fap fap fap
<Botje> :p
<Botje> mmm, breakfast.
<Botje> ?t (,,,)
<lambdabot> Maybe you meant: tell time tiny-url todo todo-add todo-delete topic-cons topic-init topic-null topic-snoc topic-tail topic-tell type . ft v
<Botje> :t (,,,)
<lambdabot> forall a b c d. a -> b -> c -> d -> (a, b, c, d)
<Botje> hurray for commas
<fasta> How can I hide every function that's in Data.List from Prelude in an import?
<nmessenger> I think you'll have to "hiding (...)" each one
<Botje> you could qualify it.
<fasta> That's the trivial solution.
Previous Page Next Page