Real World Haskell의 어느 부분이 현재 쓸모 없거나 나쁜 습관으로 간주됩니까?
Real World Haskell 의 19 장 에서 많은 예제가 Control.Exception
.
그래서이 책의 내용 중 일부는 실제로 쓸모없고 더 이상 공부할 가치가 없다고 생각합니다. 결국 6 년이 지났습니다. 저의 유일한 다른 참고 자료는 Learn You a Haskell For Great Good 이지만 훌륭한 책이지만 RWH에 비해 훨씬 더 기본적입니다.
이전에 책을 읽은 사람이 책의 어느 부분이 더 이상 관련이 없는지에 대해 조언 해 주시겠습니까? 특히 책의 후반부에있는 장에서는 소프트웨어 트랜잭션 메모리, 동시 프로그래밍, 소켓 프로그래밍 등이 있습니다.
편집 : 이것은 2008 년 12 월에 출판 된 책의 판에 관한 것으로, 오늘 (2017 년 11 월) 현재 유일하게 알려진 판입니다.
RWH의 주요 이슈
그것은 낡았다. RWH는 GHC 버전 6.8이 사용되는 시점에 작성되었습니다. 6.8 은 기본 버전 3.0.xx를 사용했습니다. 6.10.1은 이미 4.0.0.0을 사용하여 많은 변경 사항 을 도입 했습니다 . 그리고 그것은 6.8에서 6.10으로 점프 한 것입니다. GHC의 현재 버전은 7.10입니다. 모나드가 변경되었습니다. 토론 현재 있습니다 제거 return
에서Monad
소위, Monad
실제 세계 하스켈의 인스턴스가 정말 현실 세계와 동기화 될 것이다.
즉, 일반 지침에 여전히 유용한 리소스입니다. 그러나 출시 이후 많은 라이브러리가 변경되었습니다.
RWH를 읽으면서 읽을 수있는 것은 Stephen Diehl의 "What I Wish I Knew When Learning Haskell" 입니다. 추가 통찰력을 제공하지만 일부 섹션은 실제로 초보자에게 친숙하지 않습니다.
총론
- 댓글을 읽어보세요. 일반적으로 주어진 단락 / 섹션이 여전히 관련성이 있는지 및 / 또는 작동하는지에 대한 정보를 포함합니다.
- 사용하려는 라이브러리 / 함수에 대한 문서를 읽으십시오. 당신이 게 으르더라도 적어도 유형을 알고 있습니다.
장에 대한 설명
이것은 RWH를 읽는 동안 내가 발견 한 것들 중 일부에 대한 간략한 개요입니다. 아마도 불완전 할 것입니다.
2 장. 유형과 기능 vs FTP
GHC 7.10 이후 .
Foldable-Traversable-Proposal 로 인해 유형 null
이 변경 되었습니다 . 많은 다른 기능과 같은 , 이전에만 정의 된 다른 많은 가에서 더 일반적인로 대체되었습니다 변종.foldr
foldl
[a]
Prelude
Foldable t => t a
11 장. 테스트 및 품질 보증
Haskell-platform 2010 또는 후반 2008 이후.
이은에 언급되어 있지만 각주 의 QuickCheck 라이브러리 예를 들어 버전 2로 버전 1에서 여러 가지 방법으로 변경, generate
지금 사용하는 Gen a
대신에 StdGen
, 그리고 기존의 기능 generate
에있다 Test.QuickCheck.Gen.unGen
.
확실하지 않은 경우 문서를 확인하십시오 .
14 장. 모나드와 15 장. 모나드를 사용한 프로그래밍
코드 브레이킹 : Applicative m => Monad m
GHC 7.10 Applicative
부터는 Monad
2007 년에 계획되지 않은, 의 수퍼 클래스입니다 .
GHC 7.10에서는
Applicative
의 수퍼 클래스가되어Monad
많은 사용자 코드를 손상 시킬 수 있습니다. 이러한 전환을 용이하게하기 위해 GHC는 이제 정의가 Applicative-Monad Proposal ( AMP ) 과 충돌 할 때 경고를 생성 합니다.
7.8.1 릴리스 정보를 참조하십시오 .
State
/ Writer
/ Reader
모나드
에서 윌 실제 상태는 일어 서서하시기 바랍니다 모나드? 섹션, 저자 주장
Monad
인스턴스 를 정의하려면 적절한 유형 생성자(>>=)
와 및에 대한 정의를 제공해야합니다return
. 이것은 우리를State
.-- file: ch14/State.hs newtype State s a = State runState :: s -> (a, s) }
즉 더 이상 사실이 없다, 때문에 State
그 친구는 지금 통해 구현된다
type State s = StateT s Identity
type Writer w = WriterT w Identity
type Reader r = ReaderT r Identity
그래서 그들은 모나드 변환기에 의해 정의됩니다.
17 장. C와의 인터페이스 : FFI
전체 장은 괜찮지 만 댓글이나 Yuras Shumovich의 블로그 에서 읽을 수 있듯이 다음 코드의 종료 자 부분은 잘못된 관행입니다.
pcre_ptr <- c_pcre_compile pattern (combineOptions flags) errptr erroffset nullPtr
if pcre_ptr == nullPtr
then do
err <- peekCString =<< peek errptr
return (Left err)
else do
reg <- newForeignPtr finalizerFree pcre_ptr -- release with free()
return (Right (Regex reg str))
으로 malloc()
사용되어야한다 free()
, new
와 delete
, allocate
와 deallocate
, 하나는 항상 올바른 기능을 사용해야합니다.
TL; DR 항상 메모리를 할당 한 동일한 할당 자로 메모리를 해제해야합니다.
외부 함수가 메모리를 할당하면 함께 제공되는 할당 해제 함수도 사용해야합니다.
19 장. 오류 처리
Error handling changed completely from 6.8 to 6.10, but you noticed that already. Better read the documentation.
Chapter 22. Extended Example: Web Client Programming
Some of the example seem to be broken. Also, there are other HTTP libraries available.
Chapter 25. Profiling and optimization
General profiling techniques are still the same, and the example (see below) is a great case study for problems that can occur in your program. But RWH is missing multi-threaded profiling, e.g. via ThreadScope. Also, lazy IO isn't concerned throughout the whole book, as far as I know.
mean :: [Double] -> Double
mean xs = sum xs / fromIntegral (length xs)
Chapter 24 & Chapter 28 (Concurrent and parallel programming & STM)
While Chapter 24. Concurrent and multicore programming and Chapter 28. Software transactional memory are still relevant, Simon Marlow's book Parallel and Concurrent Programming in Haskell focuses solely on concurrent and parallel programming and is pretty recent (2013). GPU programming and repa are completely missing in RWH.
Chapter 26. Advanced library design: building a Bloom filter
As with the other chapters, the general guidelines of the design library is still well written and relevant. However, due to some changes (?) concerning ST
, the result cannot be compiled anymore.
Chapter 27. Network programming
It's still mostly up to date. After all, network programming doesn't change so easily. However, the code uses deprecated functions bindSocket
and sClose
, which should be replaced by bind
and close
(preferably via qualified import). Keep in mind that it's very low-level, you might want to use a more specialized high-level library.
Appendix A. Installing GHC and Haskell libraries
GHC 6.8 was the last version before the Haskell Platform has been introduced. Therefore, the appendix tells you to get GHC and Cabal by hand. Don't. Instead, follow the instructions on the haskell.org download page.
Also, the appendix doesn't tell you about Cabal sandboxes, which were introduced in Cabal 1.18 and free you from dependency hell. And of course, stack
is missing completely.
Missing content
Some topics are not discussed in RWH at all. This includes streaming libraries such as pipes and conduit, and also lenses.
There are several resources out there for those topics, but here are some links to introductions to give you an idea what they're about. Also, if you want to use vectors, use the vectors
package.
Control.Applicative
RWH uses Control.Applicative
's (<$>)
at several points, but doesn't explain Control.Applicative
at all. LYAH and the Typeclassopedia contain sections on Applicative
. Given that Applicative
is a superclass of Monad
(see above), it's recommended to learn that class by heart.
Furthermore, several operators of Control.Applicative
(and the typeclass itself) are now part of the Prelude
, so make sure that your operators don't clash with <$>
, <*>
and others.
Lenses
- Video by Edward Kmett (author of
lens
) - Video by Adam Gundry "Lenses: compositional data access and manipulation"
- Introduction and tutorial by Jakub Arnold
Streaming libraries
- Conduit Overview by Michael Snoyman (author of
conduit
) - Pipes tutorial by Gabriel Gonzales (author of
pipes
, included in thepipes
package)
Tooling
- version 1.18 of Cabal, which introduced sandboxes
stack
, a cross-platform program for developing Haskell projectsghc-mod
, a backend for vim, emacs, Sublime Text and other editors
New/missing language extensions and GHC changes
- runtime type polymorphism (
:i ($)
has changed tremendously) -XTypeInType
-XDataKinds
-XGADT
-XRankNTypes
-XGenericNewtypeDeriving
-XDeriveFunctor
- any other extension that happened after 6.6
'Programing' 카테고리의 다른 글
ResultSet을 JSON으로 가장 효율적으로 변환합니까? (0) | 2020.08.14 |
---|---|
소켓 프로그래밍과 Http 프로그래밍의 차이점 (0) | 2020.08.14 |
SQL ANSI-92 표준이 ANSI-89보다 더 잘 채택되지 않는 이유는 무엇입니까? (0) | 2020.08.14 |
PowerShell은 상수를 지원합니까? (0) | 2020.08.14 |
왜 RGB가 아닌 RGB입니까? (0) | 2020.08.14 |