FlexibleContexts
複雑な型クラス制約を書くためのGHC拡張
どう複雑 #??
↓たぶん間違ってる
こういう型注釈が書ける
code:hs
intAdd :: Num Int => Int -> Int -> Int
intAdd = (+)
defaultではNum a => a -> a -> aとしか書けない
「Int -> Int -> Int型である」かつ「そのIntはNum型クラスのインスタンスでないといけない」」ということを表現している #??
defaultでIntはNumのインスタンスだが、Int, Numじゃなくて両方自作のものを考えたほうがわかりやすいmrsekut.icon
これを読んでひとまず↑こう理解したが、これで正しいのかわかっていないmrsekut.icon
参考
https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-FlexibleContexts
haskell - What is the FlexibleContexts extension good for? Could you please explain it using a simple example? - Stack Overflow
https://qiita.com/YoshikuniJujo/items/a7146d041f88ba00d574
https://haskell.jp/blog/posts/2018/about-ghc-exts-1.html
よくわからん