I've done a personal list in Haskell like this: (2,(1,1),3) -> List [Num 2, List [Num 1, Num 1], List [Num 3]].
This is how I made it:
data SList a = Num a | List [SList a] deriving Show
emptySList :: SList a
emptySList = (List [])
consElem :: a -> SList a -> SList a
consElem x (List y) = (List ((Num x) : y))
consList :: SList a -> SList a -> SList a
consList a b = (List [a,b])
I manage to form this list (List [Num 2, List [Num 1, Num 1], List [Num 3]]) using consElem and consList like this:
consElem 2 $ consList (consElem 1 $ consElem 1 emptySList) $ consElem 3 emptySList
I wonder how can I transform a SList in a normal list. For example if I have this SList: List [Num 2, List [Num 1, Num 1], List [Num 3]] it should become [2,1,1,3].
My attempt:
atomToNormal x
| null x = []
| otherwise = slistToList (head x) ++ atomToNormal (tail x)
slistToList :: SList a -> [a]
slistToList (List x) = atomToNormal x
slistToList (Num x) = [x]
SListis a tree type, so any tree traversal should work.)onebyone (Num x) = xatomToNormal x | null x = [] | otherwise = (onebyone $ head x) : atomToNormal (tail x)slistToList (List x) = atomToNormal x(onebyone $ head x) :toslistToList (head x) ++(and handle theNumcase inslistToList).No instance for (Num (SList [t0]))slistToList :: SList a -> [a]in your code and see if you get a better error message. :-)