Skip to content

Instantly share code, notes, and snippets.

@Icelandjack
Last active June 13, 2017 12:51
Show Gist options
  • Save Icelandjack/5bdaea3692891a1ca3fbe6b7bbfd4cef to your computer and use it in GitHub Desktop.
Save Icelandjack/5bdaea3692891a1ca3fbe6b7bbfd4cef to your computer and use it in GitHub Desktop.
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
Copy link
Author

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

@Icelandjack
Copy link
Author

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