본문 바로가기

프로그래밍 기술 노트/Functional Study

Clojure 에서 모나드는 필요없다?

https://grishaev.me/en/no-monads/

 

I will never let monads be in a Clojure project

Sounds a bit aggressive, doesn’t it? Well, let me explain. Monads are fine while you’re playing with them in Haskell. But don’t bring them to Clojure. They are completely foreign beings to Clojure ecosystem. Besides the technical issues, there is a problem

grishaev.me

Clojure에서도 monad 라이브러리가 있긴하지만..

위 글에서는 하스켈에서 모나드를 사용하는것은좋지만 clojure에 까지 모나드를 끌여들이지 마라 라는 내용.

단순히 clojure는 code is data 이니까 코드를 넘기고 분해하고 어쩌고 해서 모나드 없이 처리할수있다는 내용이 아니라 모나드 개념을 clojure에 끌여들이지 말라는 내용이다.

1. Railway Programing 은 장난감이다. 

 ROP 가 안좋다는 것이 아니라 실제 업무에서 사용할때 힘들다, 하즈켈은 몰라도 모나드가 기본 개념이 아닌 프로그래밍 랭기지에서, 또는 이곳저곳 라이브러리를 가져다쓸때 결국 사용하는 모든 함수를 래핑해줘야 된다.

2. Error 모나드는 Try-Catch로 묶는것과 결과적으로 똑같다. Try-Catch 가 goto의 확장이긴 하지만.. 결과적으로 ABC 에서 B에서 오류가 발생하여 C를 스킵하는것과 C에서 아무것도 안하는것과 큰 차이가 없고...

3. clojure 는 동적언어이기 때문에 필요가 없다 - nil로 충분하다.

4. 팀에서 너만 안다 - 하즈켈이야 모나드를 아는것이 당연하지만 다른언어는 그렇지 않다.

결론적으로 다른 언어(모나드가 없는언어) 에 모나드를 끌어들이지 말라는 내용.

 

무조건적인 동의는 힘들지만, 어느정도 일리는 있는 내용인것같다.

실제로 F# 에서 ROP 를 설명해준 사람도 이번에 무조건적으로 ROP 를 사용하지 말라면서 글을 올렸다

https://fsharpforfunandprofit.com/posts/against-railway-oriented-programming/

 

Against Railway-Oriented Programming | F# for fun and profit

This post is part of the 2019 F# Advent Calendar. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. Six and half years ago, I wrote a post and did a talk on what I called “Railway Oriented Programming”. It w

fsharpforfunandprofit.com

(확인해보면 비슷한 내용이 있다. Reinventing try/catch 항목 참고)

 

ROP, 모나드를 공부해서 나쁠것은 없다. 해당 내용도 이것이 좋지 않다는것이 아니라 타 언어에 어거지로 넣지 말라는 것에 가깝다.

728x90