Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern Synonyms for Return and :>>= #17

Open
Icelandjack opened this issue Apr 30, 2016 · 7 comments
Open

Pattern Synonyms for Return and :>>= #17

Icelandjack opened this issue Apr 30, 2016 · 7 comments

Comments

@Icelandjack
Copy link

pattern RETURN :: a -> Program instr a
pattern RETURN x <- (view -> Return x)

pattern BIND :: instr a -> (a -> Program instr b) -> Program instr b
pattern BIND x k <- (view -> x :>>= k)

Bikeshed names.

@Icelandjack Icelandjack changed the title Pattern Synonyms for Return and ` Pattern Synonyms for Return and :>>= Apr 30, 2016
@HeinrichApfelmus
Copy link
Owner

Looks intriguing!

Is it really necessary for the pattern synonym to be all caps?

Since which version of GHC are pattern synonyms supported? I would like to add a conditional to keep backwards compatibility with older compilers.

@Icelandjack
Copy link
Author

Icelandjack commented May 6, 2016

The names I chose are tentative due to a chronic lack of imagination, conditional usage in lens

#if __GLASGOW_HASKELL__ >= 710
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
#endif
#if __GLASGOW_HASKELL__ >= 710
  -- * Pattern Synonyms
  , pattern Wrapped
  , pattern Unwrapped
#endif

(note pattern before the export)

#if __GLASGOW_HASKELL__ >= 710

pattern Wrapped a <- (view _Wrapped -> a) where
  Wrapped a = review _Wrapped a

pattern Unwrapped a <- (view _Unwrapped -> a) where
  Unwrapped a = review _Unwrapped a

#endif

@Icelandjack
Copy link
Author

They may be made (explicitly) bidirectional like the Head pattern in the user guide

@HeinrichApfelmus
Copy link
Owner

Hm, I would very much like to name the patterns Return and Bind, of course. Unfortunately, these names are (essentially) already taken by the ProgramView type, so this would either have to break backward compatibility or introduce weird names for the patterns. I have to think about this.

@Icelandjack
Copy link
Author

Returner and Binder?

@FranklinChen
Copy link

Any more thoughts about introducing pattern synonyms?

@turion
Copy link
Contributor

turion commented Sep 6, 2023

It seems that pattern synonyms would only be useful for Program, not for ProgramT. I for my part only use ProgramT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants