haskell-issues icon indicating copy to clipboard operation
haskell-issues copied to clipboard

(`evalState` S.empty) looks stupid

Open Gurkenglas opened this issue 8 years ago • 7 comments

I'm not sure whether this should look this stupid and I should change my approach, or we're just missing an alias.

Gurkenglas avatar Mar 25 '16 05:03 Gurkenglas

Not sure where I've ever seen this idiom?

mstksg avatar Mar 25 '16 05:03 mstksg

http://ircbrowse.net/browse/haskell?q=%28%60evalState%60+S.empty%29 http://ircbrowse.net/browse/haskell?q=flip+evalState http://ircbrowse.net/browse/haskell?q=flip+execState http://ircbrowse.net/browse/haskell?q=flip+runReaderT http://ircbrowse.net/browse/haskell?q=flip+evalStateT etc.

Gurkenglas avatar Mar 25 '16 07:03 Gurkenglas

ah. i usually do flip evalState x, things like that. (evalState x) does look a bit silly, but flip evalState x seems pretty mundane to me.

that being said, the only reason runStateT has the order that it does is to be a hack using record accessors, I think:

data StateT s m a = StateT { runStateT :: s -> m (a, s) }

so you get

runStateT :: StateT s m a -> (s -> m (a, s))

for "free". I always felt like this was an abuse of record syntax, but :|

flip runState looks pretty nice to me. in any case, having an alias for flip runState sounds like a pretty bad sort of API bloat or fairnbairn-threshold-failing thing :/

mstksg avatar Mar 25 '16 07:03 mstksg

Right about the bloat, but both flips have their place. My intuition does tell me runStateT is the correct one, because it and evalState etc. often allow eta reduction. Only sometimes the initial state is constant and I wonder.

Gurkenglas avatar Mar 26 '16 12:03 Gurkenglas

This has already been proposed and there's even a patch: https://phabricator.haskell.org/D1219, https://ghc.haskell.org/trac/ghc/ticket/10843. However:

My conclusion was that support for the extension was very mixed, and that I do not think the extension makes sense without overall approval from the community. I am not planning on pushing this any further.

neongreen avatar Apr 05 '16 10:04 neongreen

Those cons are stupid!

It's harder to read than the alternative.

Subjective.

Creating a language extension to get rid of a single character is overkill and unnecessary.

Overkill yes, unnecessary no - it's literally what needs to happen to get rid of that character (right?)

You can already get rid of the $ by just adding parentheses.

$ was introduced in the first place to get rid of parentheses! The preference ordering is () < $ < _.

More and more syntactic "improvements" just fragment the language.

That can be said about any syntactic improvement, and this is the way we've been left to get to the mythical Haskell'.

Although this is consistent with record syntax, record syntax without parents was a mistake originally.

If those are the same cons that were brought up here, see above.

Why do we need approval to introduce language extensions anyway, instead of me being able to import that patch like a library?

Gurkenglas avatar Apr 06 '16 05:04 Gurkenglas