Re: Réf. : [Haskell-beginners] a problem

Stephen Tetley stephen.tetley at gmail.com
Fri Jun 25 11:36:53 EDT 2010


On 25 June 2010 14:33,  <corentin.dupont at ext.mpsa.com> wrote:
> Hello,
> I would do (not that concise):
>
> toMaybe :: Music_Data_ -> (Maybe Note, Maybe Direction, Maybe Sound)
> toMaybe (Music_Data_1 n) = (Just n, Nothing, Nothing)
> toMaybe (Music_Data_4 d) = (Nothing, Just d, Nothing)
> toMaybe (Music_Data_9 s) = (Nothing, Nothing, Just s)
>
> catMaybes3 (a,b,c) = (catMaybes a, catMaybes b, catMaybes c)
>
> sortOutMusicData :: [Music_Data_] -> ([Note],[Direction],[Sound])
> sortOutMusicData = catMaybes3 . unzip3 . map toMaybe
>
>
> Corentin


Hi Corentin

Why would you do that though?

It's doing quite a bit more work - introducing the extra constructors
through the Nothing/Just's and extra traversals through the three
catMaybe's in the post-processing step. And its longer too...


More information about the Beginners mailing list