Andy Melnikov (nponeccop) wrote,
Andy Melnikov
nponeccop

Паттерны - литература

First Class Patterns (2000) by Mark Tullsen

..Pattern matching has its problems: it conflicts with data abstraction; it is complex (at least in Haskell, which has pattern guards, irrefutable patterns, n+k patterns, as patterns, etc.); it is a source of runtime errors; and lastly, one cannot abstract over patterns as they are not a first class language construct. This paper proposes a simplification of pattern matching that makes patterns first class. The key idea is to treat patterns as functions of type a -> Maybe b i.e., thus, patterns and pattern combinators can be written as functions in the language.

Собственно, предлагается генерировать для каждого конструктора Сon типа b две функции - Con :: a -> b и Con# :: b -> Maybe a и позволить использовать любые функции типа b -> Maybe a в тех местах, где сейчас в Хаскеле можно использовать паттерны.
Subscribe

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments