LoginSignup
2
2

More than 5 years have passed since last update.

do 記法で整数リスト生成

Posted at
num.hs
data MyList a r = ML {list::[a], result ::r}

instance Integral a => Monad (MyList a) where
    return r = ML [] r
    ML l r >>= f = let res = f r in ML (l ++ list res) (result res)

instance (Integral a, Integral b) => Num (MyList a b) where
    fromInteger a = ML ([fromIntegral a]) (fromIntegral a)

main = print . list $ do
    1   
    2   
    3   
    4   
    5   

できるかな、と思って試行錯誤でやってみた。型クラスがまだよくわかってない。

2
2
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
2
2