haskell-jp / questions #104

@Sakae has joined the channel
@ has joined the channel
フォーマッタとして hindent を使っている人はいませんか?
CPPを使っていると、ことごとくフォーマットできずにエラーになるんですが、そういうものですか?
... Replies ...
@aja has joined the channel
@goma11 has joined the channel
Hackage の upload 機能が死んでいるようなのですが、どこに連絡すればいいですか?
Hackageには書かれてないように思いました。
... Replies ...
@MaxBruchDev has joined the channel
https://haskell.jp/blog/posts/2020/strict-gotchas.html
strictは!をつけてくれるのですが、!のseqではなくdeepseqに置き換えたい場合はどうすればいいでしょうか。
... Replies ...
bunny_hopper isolated
@bunny_hopper isolated has joined the channel
Haskellのコードが書かれた大きなファイルを分割したいです。
そのため関数の依存グラフが欲しいのですが、SourceGraphはもうメンテされてないようです。
Haskellの関数の依存グラフを可視化するツールとかサービスは、他にありませんか?
... Replies ...
haskellの事をAIに質問していたら、sha256な文字列に出会いました。
ask AI この鬼のように長いsha256な文字表現を短縮したいです。イメージは
sed 's/hexDigit x 64/SHA256/g'
これをparsecで実現するには、どうしたら良いのでしょうか?
... Replies ...
@Shogo has joined the channel
@ has joined the channel
参照されていないモジュールを指摘してくれるツールってありますでしょうか?
golangでは、コンパイラーに厳しい指導をされたような。
... Replies ...
@ has joined the channel
base パッケージの versioning policy をさがしているのですが、見つけられないでいます.どなたかご存知でしょうか?
... Replies ...
@ has joined the channel
@ has joined the channel
callCCの型はなぜ`forall r m a. ((forall b. a -> ContT r m b) -> ContT r m a) -> ContT r m a`ではなく`forall r m a b. ((a -> ContT r m b) -> ContT r m a) -> ContT r m a`なのでしょうか
実際`callCC' f = callCC (\exit -> f $ (\ a -> absurd <$> exit a))`とすれば前者の型にでき、前者の型のほうが脱出用の継続(`callCC (\exit -> ...)`のexit)の返り値の型が制限されず便利であるように思えます
... Replies ...
vector-13.0.0 における newtype に対する Unbox 実装の質問です。
(1) UnboxViaPrim を使う方法と (2)『`GeneralizedNewtypeDeriving`』を使う方法 [^1] は、どちらを好むべきですか。 U.Vector を使うだけなら、大きな差は無いと思って良いでしょうか。
[^1]: ( 冒頭 2 番目のコードブロックの例)
@zackey has joined the channel
Masaaki Saitow
@Masaaki Saitow has joined the channel
RecordWildCards 有効にすると、
インポート元で定義済みフィールド名とかさなる名前の

"shadows the existing binding"

の警告が出なくなるみたいなんですが、
そういうものでしょうか?

RecordWildCards を有効にすると暗黙に有効にされる
DisambiguateRecordFields の効果なのかと思ったけどそういうわけでもないみたいです.

module M where

data R = R { x :: String }

{-# LANGUAGE RecordWildCards #-}

import M

inc :: Int -> Int
inc x = x + 1

getX :: R -> String
getX m = x m
@milran has joined the channel
@りょー has joined the channel
パターンマッチで分けられた関数定義の一行一行`f p1 p2 ... pn = e`のことを何と呼びますか?
Haskellのいくつかの文献では`equation`と呼ばれているようですが、`clause`というのも見かけます。
日本語の文献では対応する用語が見当たらなかったのですが、日本語だと何というのでしょうか?

また、関数定義をデータ型として表現するときに、
data FunDecl = FunDecl String [([Pattern], Expr)]

と書くとして、`([Pattern], Expr)` にはどんな名前をつけますか?
case式`case e of {p1 -> e1; p2 -> e2; ... pn -> en}` に含まれる`p1 -> e1`は、HaskellではAlternativeと呼ばれていますが、パターンが複数になると何と呼ばれるのでしょう?
... Replies ...
Haskellのライブラリをどのくらいの粒度でパッケージ分割したらいいのかの基準が自分の中でまだ整理が付いていないのですが、良い資料をご存知の方、もしくは考えをお持ちの方はいらっしゃいますか?

以前、いわゆる「Internalモジュール」パターンは間違っていて、Internalモジュールが作りたくなったらパッケージ分割の合図だろうといった旨の↓の記事を見まして。
記事の内容には完全に同意なのですが、すると、究極的にはなるべく細かく分割するのがよいのではないかと思うようになってしまいました。
分割を止める基準、つまりトレードオフの「分割すべきでない」側の壁がどの辺りにあるのかが分からなくなっています。

http://nikita-volkov.github.io/internal-convention-is-a-mistake/
... Replies ...
Haskell で JSON を受け取って JSON を返す簡単なAPIサーバー(インメモリのキャッシュや openapiやドキュメントの自動生成があるとなおよい)を立てる場合どのようなスタックを使いますか?

参考となるレポジトリなどあれば教えてもらえると助かります.
... Replies ...
@ has joined the channel
@ryoppippi has joined the channel
@高橋紀美 has joined the channel
以下、timeout の抜粋です。
最近の timeout は、TimeManagerを使い「時間切れのどきだけ」スレッドが作られます(forkIOWithUnmask)。
(gitでlog を読むと高野さんのアイディアらしい。)
handleTimeoutで作られるこのスレッドは、どこにもブロックする箇所がないので、すぐに消滅しそうです。
しかし、cleanupTimeoutでわざわざkillThreadしています。
このkillThreadは必要なのでしょうか?

Haskell
timeout :: Int -> IO a -> IO (Maybe a)
timeout n f
    | n <  0    = fmap Just f
    | n == 0    = return Nothing
    | otherwise = do
        -- In the threaded RTS, we use the Timer Manager to delay the
        -- (fairly expensive) 'forkIO' call until the timeout has expired.
        --
        -- An additional thread is required for the actual delivery of
        -- the Timeout exception because killThread (or another throwTo)
        -- is the only way to reliably interrupt a throwTo in flight.
        pid <- myThreadId
        ex  <- fmap Timeout newUnique
        tm  <- getSystemTimerManager
        -- 'lock' synchronizes the timeout handler and the main thread:
        --  * the main thread can disable the handler by writing to 'lock';
        --  * the handler communicates the spawned thread's id through 'lock'.
        -- These two cases are mutually exclusive.
        lock <- newEmptyMVar
        let handleTimeout = do
                v <- isEmptyMVar lock
                when v $ void $ forkIOWithUnmask $ \unmask -> unmask $ do
                    v2 <- tryPutMVar lock =<< myThreadId
                    when v2 $ throwTo pid ex
            cleanupTimeout key = uninterruptibleMask_ $ do
                v <- tryPutMVar lock undefined
                if v then unregisterTimeout tm key
                     else takeMVar lock >>= killThread
        handleJust (\e -> if e == ex then Just () else Nothing)
                   (\_ -> return Nothing)
                   (bracket (registerTimeout tm n handleTimeout)
                            cleanupTimeout
                            (\_ -> fmap Just f))
... Replies ...
Masaya Igarashi
@Masaya Igarashi has joined the channel