関数型プログラミング言語Haskell Part33

■ このスレッドは過去ログ倉庫に格納されています
1デフォルトの名無しさん
垢版 |
2020/02/10(月) 18:17:36.49ID:L6eYQqyh
関数型プログラミング言語 Haskell について語るスレです。

Haskell Language(公式サイト)
https://www.haskell.org/
日本Haskellユーザーグループ - Haskell-jp
https://haskell.jp/

前スレ
関数型プログラミング言語Haskell Part32
https://mevius.5ch.net/test/read.cgi/tech/1548720347/
2020/11/09(月) 19:55:38.03
rootsInternal :: Quadratic -> Double -> Roots

rootsInternal q d

 = let

    two_a   = 2.0 * (a q)

    realpart  = - (b q) / two_a

    dside d  = (sqrt d) / two_a

    dpart   = dside d

    complexpart = dside (-d)

  in if d==0

    then   -- Discriminant is zero, (single) root is real

      Root $ realpart :+ 0

    else

    if d<0

    then   -- Discriminant is negative, roots are complex

      Roots (realpart :+ complexpart) (realpart :+ (-complexpart))

    else   -- Discriminant is positive, all roots are real

      Roots ((realpart + dpart) :+ 0) ((realpart - dpart) :+ 0)


のlet 〜 in みたいなのを

rootsInternal q d
 | d==0   = ...
 | d<0    = ...
 | otherwise = ...

みたいな書き方の時にもやりたいんです
2020/11/09(月) 19:58:42.43
おっと無用な改行が一々入っちゃった。。。
■ このスレッドは過去ログ倉庫に格納されています
5ちゃんねるの広告が気に入らない場合は、こちらをクリックしてください。

ニューススポーツなんでも