Skip to content

Instantly share code, notes, and snippets.

@rampion
Created May 4, 2011 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rampion/955714 to your computer and use it in GitHub Desktop.
Save rampion/955714 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ScopedTypeVariables,Rank2Types #-}
module Temp where
newtype Mu a = Mu (Mu a -> a)
replaceMthNth :: Int -> Int -> a -> [[a]] -> [[a]]
replaceMthNth = ( \(replaceNth :: forall b.Int -> 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 :: forall b.Int -> 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
)
) :: (forall b.Int -> b -> [b] -> [b]) -> (forall b.Int -> b -> [b] -> [b])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment