Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
{-# 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
Something went wrong with that request. Please try again.