Jump to content

Descompactar uma lista de pares usando fold


Moises

Recommended Posts

Usando o foldr, defina  a função descompactaFold ::  [(a, b)] -> ([a], ) que transforma uma lista de pares ordenado em um par ordenado onde o primeiro elemento ´e uma lista dos primeiros componentes dos pares ordenados e o segundo elemento é uma lista dos segundos componentes dos pares ordenados.

descompactaFold [ ( 1 , 2 ) , ( 3 , 4 ) , ( 5 , 6 ) , ( 4 , 5 ) ] == ( [ 1 , 3 , 5 , 4 ] , [ 2 , 4 , 6 , 5 ] ) 

descompactaFold [ ( 1 , 2 ) , ( 3 , 4 ) , ( 5 , 6 ) , ( 4 , 5 ) , ( 5 , 6 ) ] == ( [ 1 , 3 , 5 , 4 , 5 ] , [ 2 , 4 , 6 , 5 , 6 ] )

Código testado, porem não funciona:

descompactaFold ::  [(a, b)] -> ([a], )
descompactaFold f v [] = v
descompactaFold f v (x:xs) = f x (descompactaFold f v xs)

 

Edited by Moises

Moises 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.