Created
May 4, 2011 15:27
-
-
Save rampion/955412 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE ScopedTypeVariables,RankNTypes #-} | |
module Temp where | |
newtype Mu a = Mu (Mu a -> a) | |
replaceMthNth :: Int -> Int -> a -> [[a]] -> [[a]] | |
replaceMthNth = ( \(replaceNth :: Int -> forall b.b -> [b] -> [b]) -> | |
-- definition of replaceMthNth in terms of some replaceNth | |
\m n v arg -> replaceNth m (replaceNth n v (arg !! m)) arg | |
)$ | |
-- y combinator | |
((\f -> (\h -> h $ Mu h) $ \x -> f $ (\(Mu g) -> g) x $ x) :: (a -> a) -> a) $ | |
(\(replaceNth :: Int -> forall b.b -> [b] -> [b]) -> | |
-- definition of replaceNth given a recursive definition | |
(\(n::Int) newVal xs -> case xs of | |
[] -> [] | |
(x:xs) -> if n == 0 then newVal:xs else x:replaceNth (n-1) newVal xs | |
) | |
) :: (Int -> forall b.b -> [b] -> [b]) -> (Int -> forall b.b -> [b] -> [b]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment