0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Functorの定義の f、t の方が良くね?

Posted at

Haskellを勉強していて、Functorの章に入ったんだけど、定義を見てふと思った。

class Functor f where
    fmap :: (a -> b) -> f a -> f b

このffunctionのfに見えてややこしい。
だって、fmapに渡すのは関数(a -> b)だけど、fに入るのってMaybeとか[]とかの型
だし。

だったらこれ、fじゃなくて typeのt にした方がいい。

class Functor t where
    fmap :: (a -> b) -> t a -> t b

こっちの方がいいよねって話。


そんなことを、ChatGPT先生に聞いてみた。

それ、確かにわかりにくいよね。
でもこのfは「Functorのf」として慣習的に使われてるだけで、別にtにしても意味はまったく同じなんだよ。初学者はtの方がピンとくるかもね。

とのこと。まぁそうですよねって感じ。


雑にまとめると、可読性を取るか言語としての美しさを取るかって話なんだと思う。
Pythonなら可読性に寄ってたかもだけど、Haskellはそういう思想じゃないからfなんだろうね。おもろいね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?