Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell point-free

Name: Anonymous 2009-12-25 17:12

I have this:


ops :: [[Char] -> [Char]]
...
fun :: [Char] -> [[Char]]
fun str = zipWith ($) ops $ words str


How do I write fun in a point-free style? Dropping the argument gives me type errors.

Name: Anonymous 2010-01-08 23:34

Help me, LaTeX's also making me use faggot quotes!

Name: Anonymous 2010-01-08 23:48

>>41
That's why I have a strict policy of writing papers only in Microsoft Word.

Name: Anonymous 2010-01-09 4:50

>>41
Those are ``expert quotes''. Stop diluting this board with your newfag antics.

Name: Anonymous 2010-01-09 6:31

>>37
I love how everyone ignores you're post because it clashes with there beliefs.

    +1 Anonymous likes this.

Name: Anonymous 2010-01-09 6:39

>>44
Ihibbit :(

Name: Anonymous 2010-01-09 13:45

>>43
0/10.
Back to /b/, please.

Name: Anonymous 2010-01-09 14:39

OP back here, still learning Haskell, and Im stuck at the technical aspects of monads.

liftM :: (Monad m) => (a1 -> r) -> m a1 -> m r
Right?
So, why doesnt liftM elem (Just 'd') (Just "dongz") work? m is Maybe, a1 is Char and r is [Char]. What's wrong?

Name: Anonymous 2010-01-09 15:01

>>47
elem :: (Eq a) => a -> [a] -> Bool

How is that going to match a1 -> r?

Name: HMA FAN 2010-01-09 15:06

>>47
I chortl'd.
elem :: Eq a => a -> [a] -> Bool
Protip: liftM2

Name: 47 2010-01-09 15:25

>>48,49
FUCK

Name: Anonymous 2010-01-09 15:26

>>47
tl;dr: use liftM2

liftM :: Monad m => (a -> b) -> (m a -> m b)
elem :: (a -> ([a] -> Bool))
liftM elem :: Monad m => m a -> m ([a] -> Bool)
liftM elem (Just 'd') :: Monad m => Maybe ([a] -> Bool)


Can you see why that doesn't work? You can't apply that to Just "dongz", because it's not a function: it is a nomad with the function in his pocket. What you really want is liftM2:

liftM2 :: Monad m => (a -> b -> c) -> (m a -> m b -> m c)
liftM2 elem :: Monad m => m a -> m [a] -> m Bool
liftM2 elem (Just 'd') (Just "dongz") :: Maybe Bool


But I won't stop here, because there's another interesting way, namely the Applicative type class. I recommend the the Typeclassopedia¹ for understanding this and its relationship to the others, but here's an introduction.

class Functor f => Applicative f where
    pure :: a -> f a -- For a monad, pure = return

    -- This is why it is called an applicative functor.
    --
    -- For any monad, you can define <*> as such:
    --   f <*> x = liftM2 ($) f x
    --
    -- There are applicatives which are not monads, such as the ZipList
    -- applicative (as far as I know).
    --
    -- E.g. in the Maybe monad this is
    --   Maybe (a -> b) -> (Maybe a -> Maybe b)
    (<*>) :: f (a -> b) -> (f a -> f b)

-- This is already defined in Control.Applicative.
instance Applicative Maybe where
    pure = Just
    Just f <*> Just x = Just (f x)
    _ <*> _ = Nothing

-- Just succ <*> Just 3 = Just 4
-- [succ, (*2)] <*> [7,8] = [8,9,14,16]
-- (zip <*> tail) [1..10] = [(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,9),(9,10)]

liftM elem :: Monad m => m a -> m ([a] -> Bool)
liftM elem (Just 'd') :: Maybe ([a] -> Bool)
(<*>) liftM elem (Just 'd') :: Maybe [a] -> Maybe Bool
liftM elem (Just 'd') <*> Just "dongz" :: Maybe Bool


Now, if you define <$> = liftM², you get a nice result:

elem <$> (Just 'd') <*> Just "dongz" :: Maybe Bool

Alternative, but equivalent answers:

pure elem <*> (Just 'd') <*> Just "dongz" :: Maybe Bool
elem `liftM` (Just 'd') `ap` Just "dongz" :: Maybe Bool


¹ http://haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf
² Or <$> = fmap, it's the same since liftM = fmap.

Name: Anonymous 2010-01-09 15:29

>>47
import Control.Applicative
liftM elem (Just 'd') <*> (Just "dongz")

Name: Anonymous 2010-01-09 15:31

>>51
Enterprise HASKAL Programmer Detected

Now you're stuck with defining a special operator for every flavour of liftM and have several problems.

Name: Anonymous 2010-01-09 15:32

>>53
Wait, I thought you meant liftM2 but it was actually a reference. A++ nice bbcode would read again

Name: Anonymous 2010-01-09 16:13

>>51
it is a nomad with the function in his pocket.
I LOVE YOU! I LOVE YOUR POST! I READ IT FIVE TIMES! KEEP POSTING!

Awarded For: the most intuitive explanation of monads ever
good job!

Name: Anonymous 2010-01-10 21:09

bampu

Name: Anonymous 2010-02-09 21:27

>>>51

Name: Anonymous 2010-02-10 18:35

>>51
This leads me to believe that Haskell is currently solving problems that will affect society in ten years or so. I predict there's a major telecom blackout because Erlang fails to do parallel garbage collection. Maybe major bank systems will crash because of a mistake in taking the wrong locks during transactions. Or perhaps an epic fail of Amazon's databases after an incorrect typecast.
Or perhaps an epic fail
/b/tards program in Haskell. I've been living a lie.

Name: Anonymous 2010-02-10 18:38

>>58
OH MY GOD!

they´re everywhere! what if they´re in my house!

HELP ME /prog/ ! please !

Name: wedding-d 2010-07-06 4:40


I got an <a href="http://www.maternityweddingdressesshop.com" title="wholesale Wedding Dresses">maternity wedding dresses</a> engagement ring for Christmas. My <a href="http://www.maternityweddingdressesshop.com" title="wholesale Wedding Dresses">maternity wedding dresses</a> boyfriend and I had been dating for almost a year and both felt the time was <a href="http://www.maternityweddingdressesshop.com" title="wholesale Wedding Dresses">maternity wedding dresses</a>right to join our lives together in holy matrimony. htmlThe month of January was spent planning our <a href="http://www.wholesale-promgowns.com " title="wholesale Wedding Dresses">wholesale prom gowns</a> perfect Alabama June wedding. My mother, two sisters and I went to Huntsville, the closest <a href="http://www.maternityweddingdressesshop.com" title="wholesale Wedding Dresses">maternity wedding dresses</a> town with a selection of bridal shops, to buy the gown that would play the leading role on my special occasion.We <a href="http://www.wholesale-promgowns.com " title="wholesale Wedding Dresses">wholesale prom gowns</a> had a wonderful time just being together and sharing silly jokes, but the <a href="http://www.wholesale-promgowns.com " title="wholesale Wedding Dresses">wholesale prom gowns</a> day soon turned serious by afternoon: still no sign of the dress of my dreams. Both sisters were ready to give <a href="http://www.wholesale-promgowns.com " title="wholesale Wedding Dresses">wholesale prom gowns</a> up and try another day in another town, but I coerced them into one more boutique.I had a good feeling as we entered the quaint little <a href="http://www.maternityweddingdressesshop.com" title="wholesale Wedding Dresses">maternity wedding dresses</a> shop filled with the scent of fresh flowers. The elderly clerk showed us several <a href="http://www.wholesale-promgowns.com " title="wholesale Wedding Dresses">wholesale prom gowns</a> beautiful gowns in my size <a href="http://www.wholesale-promgowns.com " title="wholesale Wedding Dresses">wholesale prom gowns</a> and price range, but none were right. As I opened the door to leave, the desperate shop owner announced she had one more dress in the back that was expensive and <a href="http://www.maternityweddingdressesshop.com" title="wholesale Wedding Dresses">maternity wedding dresses</a> not even my size, but perhaps I <a href="http://www.wholesale-promgowns.com " title="wholesale Wedding Dresses">wholesale prom gowns</a> might want to look at it anyway. When she brought it out, I squealed in delight.

Name: Anonymous 2012-02-12 12:31

Cartesian product in Haskell:

(<*>) . ((,) <$>)

Point-free + Applicative = awesome.

Name: Anonymous 2012-02-12 14:12

Haskell is constipated shit.

Name: Anonymous 2013-01-18 23:41

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List