lomeo: (лямбда)
[personal profile] lomeo
Я вот жаловался [livejournal.com profile] thesz, что в Haskell нет аналога partial function в Scala, чтобы можно было легко строить конструкции аналогично Erlang'овского receive (я говорю о синтаксисе). Однако механизмы есть. Правда, я нашёл пока только для IO.

import Prelude hiding (catch)
import Control.Exception

e `patternFail` h = e `catch` \(PatternMatchFail _) -> h

apply handlers = \x -> foldl1 patternFail (map ($x) handlers)

-- *Main> apply [\[1]->putStrLn "a", \[2]->putStrLn "b", \[3]->putStrLn "c"] [2]
-- b


Список здесь всего лишь пример, можно сделать и по другому (varargs?)
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

lomeo: (Default)
Dmitry Antonyuk

April 2024

S M T W T F S
 123456
7891011 1213
14151617181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 23rd, 2025 10:15 pm
Powered by Dreamwidth Studios