Last active
June 15, 2022 13:10
-
-
Save ncaq/fb4ba6ede5dbde3170822fd21c249930 to your computer and use it in GitHub Desktop.
[Rubyist のための他言語探訪 【第 13 回】 Prolog](https://magazine.rubyist.net/articles/0021/0021-Legwork.html) のHaskell実装
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
import Control.Monad | |
import qualified Data.List as L | |
main = print (兄弟 sally erica :: [Bool]) | |
兄弟 x y = do | |
xa <- 子の親 x | |
ya <- 子の親 y | |
guard $ xa == ya | |
pure True | |
子の親 x = 子の母 x <|> 子の父 x | |
子の母 x | |
| x == sally = pure judy | |
| otherwise = empty | |
子の父 x | |
| x `L.elem` [sally, erica] = pure tom | |
| x == tom = pure mike | |
| otherwise = empty | |
erica = "erica" | |
judy = "judy" | |
mike = "mike" | |
sally = "sally" | |
tom = "tom" |
この範囲だけ見るとRDBMSだけで良いのではという気もしますね。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
自由変数の概念が無いのでそれぞれ固定化された方向にしかデータベースを構築出来ないのが残念。
全部取り出して実行するとかは大きくなると効率悪すぎるので出来ないですし。
この範囲だけ見るとTypeScriptとかで実装した時とさほど変わらなく見えるかもしれない。
やはりこういう特化したコードの場合Prologの優位性は残ったままか。