mno2
Haskell 趣學指南

Updated 2 years ago

Kenneth Lo (@closer76) started discussion #13

2 years ago · 0 comments

Open

注意到我們是寫 instance Functor Maybe where 而不是 instance Functor (Maybe m) where,就像我們在寫 YesNo 時的 Maybe 一樣。Functor 要的是一個接受一個型別參數的型別構造子而不是一個具體型別。如果你把 f 代換成 Maybe。fmap 就會像 (a -> b) -> Maybe a -> Maybe b。但如果你把 f 代換成 (Maybe m),那他就會像 (a -> b) -> Maybe m a -> Maybe m b,這看起來並不合理,因為 Maybe 只接受一個型別參數。

Build Our Own Type and Typeclass (Edit this file)

「就像我們在寫 YesNo 時的 Maybe 一樣」放的地方怪怪的...

在譯文中看起來像是指 "instance Functor Maybe where";但實際上它指的是 "instance Functor (Maybe m) where" 這種寫法。因此想辦法放在「而不是」之後應該會好一點。

No comments on this discussion.


to join this conversation on GitBook. Already have an account? Sign in to comment
Notifications

You’re not receiving notifications from this thread.


1 participant