I have just started trying Haskell after using Python, and I'm facing a lot of problems understanding it
for example after I tried to make a new type called ListBag and writing a simple function to convert list to ListBag I can't go back and do anything with that data:
data ListBag a = LB [(a,Int)] deriving (Show,Eq)
fromList :: (Ord a) => [a] ->ListBag a
fromList xs = LB [ y| y<- ys]
where ys = toList(fromListWith (+) [(x, 1) | x <- xs])
a :: [Integer]
a=[1,1,1,1,1,1,2,2,2,3,3,3,3,4,5,5]
b = fromList a
Now b
is:
LB [(1,6),(2,3),(3,4),(4,1),(5,2)]
and because b
is b :: ListBag Integer
it can't be mapped or ...
So how can I convert it to List again?
question from:
https://stackoverflow.com/questions/65853042/how-to-convert-my-own-data-constructor-to-list-in-haskell 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…