Created
April 16, 2012 18:05
-
-
Save kakkun61/2400393 to your computer and use it in GitHub Desktop.
The Little Schemer (ver. Haskell), Scheme 手習い (Haskell 版)
This file contains 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
-- Scheme 手習い 5章 p.83 | |
-- The Little Schemer Section 5 | |
rember_star :: (Eq a, Eq b) => a -> [b] -> [b] | |
rember_star _ [] = [] | |
rember_star e (x:xs) = | |
case x of | |
ys@(_:_) -> (rember_star e ys) : (rember_star e xs) | |
z | e == z -> rember_star e xs | |
_ -> x : rember_star e xs | |
-- haskeller.hs:7:34: | |
-- Could not deduce (a ~ [t0]) | |
-- haskeller.hs:8:14: | |
-- Could not deduce (b ~ [t0]) | |
{- | |
このままの構造だと実装は無理な気がする。どうすべきか。 | |
I think that rember_star cannot be implemented with this structure. How should I implement it? | |
-} | |
{- | |
; quote The Little Schemer | |
(define rember* | |
(lambda (a l) | |
(cond | |
((null? l) (quote ()) | |
((atom? (car l)) | |
(cond | |
((eq? (car l) a) (rember* a (cdr l))) | |
(else (cons (car l) (rember* a (cdr l)))))) | |
(else (cons (rember* a (car l)) (rember* a (cdr l))))))) | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
少なくともリストの要素の型が全て同じじゃないと Haskell で実装できないよな。