Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GHC Trac #10843

Motivating examples for https://ghc.haskell.org/trac/ghc/ticket/10843, https://ghc.haskell.org/trac/ghc/wiki/ArgumentDo

This should allow

curry $ \case

without the dollar giving us weird code

data N = O | S N

add :: N -> N -> N
add =     fix
 \add  -> curry 
 \case -> 
   (O,   b) -> b
   (S a, b) -> S (add a b)

Good for defining a recursive ('curried') binary data type in GHCi without too much noise (as if this matters)

curry \case (Just x, Just y) -> Just (x <> y); _ -> Nothing
@Icelandjack

This comment has been minimized.

Copy link
Owner Author

@Icelandjack Icelandjack commented Jun 7, 2017

I propose an essential language extension, -XCurryCase which lets you write curry \case as \currycase 🤣

@Icelandjack

This comment has been minimized.

Copy link
Owner Author

@Icelandjack Icelandjack commented Jun 13, 2017

The recent Key Monad lets us mimic Arrow notation in user code

-- addA :: Arrow a => a b Int -> a b Int -> a b Int
-- addA f g = proc $ \z -> do
--     x <- f -< z
--     y <- g -< z
--     return $ (+) <$> x <*> y
addA :: Arrow a => a b Int -> a b Int -> a b Int
addA f g = proc \z -> do
    x <- f -< z
    y <- g -< z
    return $ (+) <$> x <*> y

compared to

addA :: Arrow a => a b Int -> a b Int -> a b Int
addA f g = proc z -> do
   x <- f -< z
   y <- g -< z
   returnA -< x + y

In an alternative universe with idiom brackets

addA :: Arrow a => a b Int -> a b Int -> a b Int
addA f g = proc \z -> do
    x <- f -< z
    y <- g -< z
    return [| x + y |]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment