sml - Error implementing the unzip function -


i want implement function gets 1 list of tuples (in size of 2) , yielding tuple of 2 separate lists.

i tried code:

fun unzip [] = ([],[])   | unzip [(a,b)] = ([a],[b])   | unzip (a,b)::ps =   (a::(#1(unzip(ps))),(b::(#2(unzip(ps)))); 

but doesn't compile, sml gives me in prompt =

need on additional ) @ end close tubple. need ( (a,b)::ps ). somehow sml thought pattern unzip (a, b) , treating :: different describing pattern. still not know when or why sml needs of parentheses needs, adding more in right place seems solve lot of errors.

your version, syntax fixes. (note, fixed syntax, did not make other improvements code possible.)

fun unzip [] = ([],[])   | unzip [(a,b)] = ([a],[b])   | unzip ((a,b)::ps) =   (a::(#1(unzip(ps))),(b::(#2(unzip(ps))))) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -