Drkcore

21 01 2010 Haskell Tweet

Write Yourself a Scheme in 48 HoursComments (4章)

効率のよいエラーの仕組みを導入。

type ThrowsError = Either LispError

みたいなのが慣れない。Either a bがaとbの両方をとるみたいに感じちゃうからか。実際に下のようにしてみると納得出来るんだけど。

ここにあった例を

int_sqrt :: Int -> (Either Int Double)
int_sqrt x | fsdx * fsdx == x  = Left fsdx  
           | otherwise = Right sdx
 where sdx = sqrt $ fromIntegral x
       fsdx = floor sdx

このように変えてみた

type Leftint = Either Int

int_sqrt :: Int -> (Leftint Double)
int_sqrt x | fsdx * fsdx == x  = Left fsdx  
           | otherwise = Right sdx
 where sdx = sqrt $ fromIntegral x
       fsdx = floor sdx

まぁそうだよなと思う。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021