Skip to content

Instantly share code, notes, and snippets.

@rampion
Created May 4, 2011 15:27
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/955412 to your computer and use it in GitHub Desktop.
Save rampion/955412 to your computer and use it in GitHub Desktop.
{-# 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