same as the pythong version but in Haskell