박준규

@curry@hackers.pub · 181 following · 103 followers

darcs hub
hub.darcs.net/vincent
Hackage
hackage.haskell.org/user/JoonkyuPark

https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.6#superclass-expansion-is-more-conservative

내가 9.4 -> 9.6 마이그레이션에서 겪고 있는 문제가 이거랑 관련이 있는거 같은데(확실치 않음)... 9.4에서는 c :: Type -> Constraint 일때 forall c. c Int 뭐 이런 조건이 있으면, 모든 c에 대해 c Int가 존재하는게 말이 안되는데도 실제로 c Int 꼴로 쓰이는 c만 고려해서 타입체크를 통과시켜줬던거 같다(이것도 확실하지 않음). 근데 9.6에선 당연히 거부당한다.

위의 내 이해가 맞다면 9.4의 constraint solving 완전 무근본이었단건데, 이건 또 믿기 어렵다(하스켈의 설계 결정에 대한 신뢰 유지한다고 하면). 어디서 내가 잘못 파악한거지.

0

책 읽다가 생소한 게 나와서 적어 본다.

패키지 attoparsec에 있는 함수 parseOnly는 청크 한 개만 다룰 수 있고 나머지 청크는 버린다. 이러면 스트림 데이터를 읽을 수가 없다. 이때 모듈 Data.Attoparsec.ByteString.Run에 있는 다음 도구를 사용하면 된다.

parseAndRestore :: Monad m =>
  RestorableInput m ByteString -> Parser a -> m (Either ParseError a)
data RestorbleInput m i = RestorableInput
  (m i)       -- ^ Get the next chunk of input, or an empty string if there is no more
  (i -> m ()) -- ^ Push a nonempty chunk of input back to the input stream
newRestorableIO
  :: IO i  -- ^ Get the next chunk of input, or an empty string if there is no more
  -> IO (RestorableInput IO i)

RestorableInput IO ByteStringByteString 청크 스트림을 표현한다. 이게 일종의 가변 상태를 가지고 있다. 이 가변 상태가 있기 때문에 앞에서 읽었지만 소모되지 않은 청크를 버리지 않고 입력에 다시 넣는 방식을 쓰는 것 같다.

이런 방식을 Incremental parsing이라고 하는 것 같다.

5
1
0
5
1
1
2
2

For my library and CLI projects, I've been writing documentation before writing any code. It helps me imagine the final interface early on, which usually leads to better design. Sure, sometimes I miss implementation details and have to revise later, but hey—it's just docs. Docs are easy to change.

This tiny habit has surprisingly big payoffs. When I focus on how things will be used rather than how they'll be built, I end up with interfaces that actually make sense.

Anyone else do this? Curious about your experience with documentation-first approaches.



RE: https://hollo.social/@hongminhee/01964c76-ef1e-7994-b3f0-57f967742566

2
1

책 제목에 포함되어 있는 단어이자 패키지 이름인 pipes가 도대체 뭐하는 건지 감이 안 잡혔는데 드디어 해당 챕터에 돌입했다. 대충 보니 스트리밍 데이터를 처리하는 패키지인 것 같다. 라이브러리 제작자가 가브리엘라 님이라니!

‘스트리밍’이라는 단어를 많이 들어보고 많이 써왔는데 정확한 의미는 뭔지 몰랐다. 스트리밍은 큰 데이터를 잘라서 전달하는 것을 의미하는 것 같다.

https://hackage.haskell.org/package/pipes

2
2
2

책에 나온 예제를 따라 하는데 결과가 책과 달라 이상했다. 코드를 한참 보다가 결국 원인을 찾았다. if 분기의 결과를 반대로 적었던 것이다.

repeatUntil
  :: Monad m
  => m chunk
  -> (chunk -> Bool)
  -> (chunk -> m ())
  -> m ()
repeatUntil getChunk isEnd f =
  repeatUntilNothing getChunkMaybe f
  where
    getChunkMaybe = do
      chunk <- getChunk
      if isEnd chunk
        then return (Just chunk)
        else return Nothing

청크가 없으면 Nothing을 리턴해야 하는데 반대로 적어버린 것이다. 덕분에 시간이 모자라서 남은 연습 문제 하나는 내일로 미뤄야겠다.

5

오늘 읽을 챕터 제목은 ‘스트리밍(Streaming)’이다. 서두에 이런 말이 나온다.

No one ever steps in the same stream twice, for it is not the same stream and they are not the same person.

ChatGPT에게 저게 유명한 말인지 물었더니 다음과 같이 대답했다.

https://chatgpt.com/share/6800e63e-07b4-800c-b32b-fef1723ef5c5

“판타 레이”가 여기서 나온 말이구나. 나는 이 말을 웹툰 “덴마”에서 처음 봤다. 무슨 뜻인지도 모르고 봤네.

1
2

책 한 챕터 다 읽었다. stm 패키지에서 제공하는 기능이 많지만 여기서는 TVar만 쓸 줄 알면 돼서 분량이 많지 않네. 다음과 같은 형식으로 웹사이트 방문자 카운터를 구현할 수 있다.

countingServer :: IO ()
countingServer = do
  hitCounter <- atomically (newTVar @Natural 0)
  serve @IO HostAny "8000" \(s, _) -> do
    count <- atomically (increment hitCounter)
    sendResponse s (textOk (countHelloText count))

increment :: TVar Natural -> STM Natural
increment hitCounter = do
  oldCount <- readTVar hitCounter
  let newCount = oldCount + 1
  writeTVar hitCounter newCount
  return newCount
2
0
0

놀라서 전파하긴 했는데 살펴보니 어떤 분은 ‘아직 모른다’라고 하시는 분도 있네요. 구체적이고 정확한 후속 보도를 아시는 분은 공유를 부탁드립니다. 저도 확인해보겠습니다.

3

놀라서 전파하긴 했는데 살펴보니 어떤 분은 ‘아직 모른다’라고 하시는 분도 있네요. 구체적이고 정확한 후속 보도를 아시는 분은 공유를 부탁드립니다. 저도 확인해보겠습니다.

1
2

@bglbgl gwyng 이게 생각해보니 ‘문법이 복잡하다’, ‘문법 요소가 적다’라는 표현이 구체적이지 않은 것 같습니다. 갑자기 언어 확장이 떠오르면서 ‘문법 안 복잡한 거 맞나?’ 싶네요. 그래서 표현을 좀 바꾸면 저는 사전에 정의된 키워드가 적을 수록 좋다고 생각합니다.

0
1

하스켈에서 $가 infix operator가 아니라 문법 요소여야 한다는 얘기에는 동의하는 사람들이 꽤 있다. 근데 1 + $ 2 + 31 + (2 + 3)으로 변환되어야 한다고 하면 다들 싫어한다ㅋㅋ 근데 나는 저것도 좋다고 본다.

2
1
1
1
2

하스켈 코드 포매터 stylish-haskell을 잘 쓰고 있습니다. Vim에서 :%!stylish-haskell이라고 입력하는 방식으로 사용하는데요, 코드에 문제가 있을 경우 코드 전체가 지워지고 다음과 같은 문자열로 대체됩니다.

<string>:1:18: error: [GHC-58481] parse error on input `!'

Vim에서 작업 중이므로 단순히 u를 눌러서 취소하면 되긴 합니다만 혹시 다른 방법이 있을까요?

하스켈 코드 포매터 stylish-haskell을 잘 쓰고 있습니다. Vim에서 :%!stylish-haskell이라고 입력하는 방식으로 사용하는데요, 코드에 문제가 있을 경우 코드 전체가 지워지고 다음과 같은 문자열로 대체됩니다.

<string>:1:18: error: [GHC-58481] parse error on input `!'

Vim에서 작업 중이므로 단순히 u를 눌러서 취소하면 되긴 합니다만 혹시 다른 방법이 있을까요?

0
curl --http1.1 --dump-header - http://localhost:8000
  • --http1.1처럼 버전을 정할 수 있다.
  • --dump-header <filename>으로 헤더를 파일로 저장할 수 있는데 파일 이름 대신 -를 적으면 헤더를 화면에 출력한다.
0

[1]에서 문자열을 다룰 때 StrictTextBuilder의 성능을 비교하는 예제에서 Builder의 성능이 더 좋다고 설명한다. 그런데 내 PC에서 같은 코드를 실행했는데 결과가 반대로 나왔다. 이상해서 문자열 길이를 늘렸더니 책에서 말한대로 나왔다.

ghci> concatSpeedTest 50000
0.004451s
0.04721s
ghci> concatSpeedTest 500000
0.062405s
0.023449s
ghci> concatSpeedTest 5000000
0.511402s
0.205632s

  1. Chris Martin, Julie Moronuki, 《Sockets and Pipes》 ↩︎

3

Yacc와 같은 파서 제네레이터에 BNF를 넣으면 파서 코드가 자동으로 생성된다. 그런데 HTTP나 ActivityPub 등의 프로토콜 스펙을 입력으로 넣으면 자동으로 코드를 구현해주는 도구 어디 없나?

1

오, Quasi-quotation 신기하다. 문자열 안에 아스키 글자를 넣으면 컴파일 에러가 나네!

library/Book.hs:221:18: error:
    • Must be only ASCII characters.
    • In the quasi-quotation: [A.string|GET ♫ HTTP/1.1|]
    |
221 |   line [A.string|GET ♫ HTTP/1.1|] <>
    |                  ^^^^^^^^^^^^^^^^
0

오, Quasi-quotation 신기하다. 문자열 안에 아스키 글자를 넣으면 컴파일 에러가 나네!

library/Book.hs:221:18: error:
    • Must be only ASCII characters.
    • In the quasi-quotation: [A.string|GET ♫ HTTP/1.1|]
    |
221 |   line [A.string|GET ♫ HTTP/1.1|] <>
    |                  ^^^^^^^^^^^^^^^^
1
0
1

책을 읽고 있는데 고퍼(Gopher)라는 고대의 프로토콜이 나왔다. 책에서 다음과 같이 아직 살아 있을 수 있는 고퍼 서버 목록을 소개한다.

고퍼 서버에 \r\n을 날리면 응답이 오는데 위 세 개 서버에 요청을 날려보니 모두 응답이 온다.

예를 들어 세 번째 고퍼 서버의 응답은 다음과 같다.(스압 주의)

i	fake	(NULL)	0
i	fake	(NULL)	0
i __  __      _        _____ _ _ _	fake	(NULL)	0
i|  \/  | ___| |_ __ _|  ___(_) | |_ ___ _ __	fake	(NULL)	0
i| |\/| |/ _ \ __/ _` | |_  | | | __/ _ \ '__|	fake	(NULL)	0
i| |  | |  __/ || (_| |  _| | | | ||  __/ |	fake	(NULL)	0
i|_|  |_|\___|\__\__,_|_|   |_|_|\__\___|_|	fake	(NULL)	0
i	fake	(NULL)	0
1MetaFilter	/MetaFilter	gopher.metafilter.com	70
isharing and discussing neat stuff on the web	fake	(NULL)	0
1Ask MetaFilter	/Ask MetaFilter	gopher.metafilter.com	70
iasking questions and getting answers	fake	(NULL)	0
1FanFare	/FanFare	gopher.metafilter.com	70
ipop culture discussion -- TV, movies, podcast, books	fake	(NULL)	0
1Projects	/Projects	gopher.metafilter.com	70
icreative work by MetaFilter community members	fake	(NULL)	0
1Music	/Music	gopher.metafilter.com	70
ioriginal musical and audio recordings by MeFites	fake	(NULL)	0
1Jobs	/Jobs	gopher.metafilter.com	70
iemployment opportunities and member availabilities	fake	(NULL)	0
1IRL	/IRL	gopher.metafilter.com	70
iorganizing meetups and community events in real life	fake	(NULL)	0
1MetaTalk	/MetaTalk	gopher.metafilter.com	70
iwhere the commuity talks about MetaFilter itself	fake	(NULL)	0
1FAQ	/FAQ	gopher.metafilter.com	70
ifrequently asked questions	fake	(NULL)	0
5
6
14
0
0
3
3
0

darcs show dependencies라고 입력하면 다음과 같이 Graphviz DOT 코드를 출력해준다!

%0 1a66e7eb Initial commit f55ce246 Book.hs: Extract file handle allocation into fileResource function f55ce246->1a66e7eb 227e4ff1 feat: Add greeting text file I/O with uppercase printing 227e4ff1->f55ce246 771b32dc Add `repeatUntilIO` helper and use it in `printFileContentsUpperCase2` 771b32dc->227e4ff1

(해커즈 퍼브에서는 graphviz를 지원합니다!)