On 17 Nov 2016, at 12:03, Edward Kmett <ekmett@gmail.com> wrote:(?) <$> fFlag <$> flagEnabled <*> flagDisabledYou probably don't want this. This performs both effects (!), regardless of the flag, but only keeps one result.-EdwardOn Wed, Nov 16, 2016 at 11:01 PM, winter <drkoster@qq.com> wrote:And here’s some other stuff i can came up with it(without obscured readability IMHO):...-- replacement for ifM in various package, similar to (>>= when)(mFlag >>= (?)) flagEnabled -- mFlag :: Monad m => m Bool$ flagDisabled-- nicer if-then-else in applicative style(?) <$> fFlag <$> flagEnabled<*> flagDisabled-- compose with predicates to define your own ififLower = (?) . isLowerifLower ‘X’ lowerupper...Basically it's a good if-then-else replacement if you’re comfortable with point-free style.On 17 Nov 2016, at 11:16, winter <drkoster@qq.com> wrote:I’m totally aware of the existence of bool, i suppose (?) is mainly used in fully application to get a different style than if-then-else syntax, say,...isGoo <- checkGooisGoo ? goo$ woo...But like what the wiki suggested, (?) can be used in some high-order situations. I like this operator because the mnemonic of questioning meaning.On 17 Nov 2016, at 11:03, David Feuer <david.feuer@gmail.com> wrote:If ifThenElse is good for RebindableSyntax, then I'm +1 on that (but I've never played with that extension, so I don't really know). I'm -1 on (?). We already have bool, which tends to be rather more useful when partially applied.
On Nov 16, 2016 9:43 PM, "winter" <drkoster@qq.com> wrote:It seems this’s a very old request, see https://wiki.haskell.org/If-then-else . I’d like to see following:ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = x ifThenElse False _ y = yinfixr 1 ? (?) :: Bool -> a -> a -> a (?) = ifThenElsein Date.Bool module, it will have advantages that:
+ It’s more composable than syntax.
+ Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes.
+ In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior.
Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.Cheers~Winter
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries