public
Last active

  • Download Gist
temp.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{-# 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])

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.