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

corentin.dupont at ext.mpsa.com corentin.dupont at ext.mpsa.com
Fri Jun 25 09:27:03 EDT 2010


Hello,

I would do (no 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



                                                                           
             Michael Mossey                                                
             <mpm at alumni.calt                                              
             ech.edu>                                                 Pour 
             Envoyé par :              beginners at haskell.org               
             beginners-bounce                                           cc 
             s at haskell.org                                                 
                                                                     Objet 
                                       [Haskell-beginners] a problem       
             23/06/2010 10:08                                              
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Can I get a suggestion for a concise way to write 'sortOutMusicData' as
described here? This is MusicXML-related.

data Music_Data_ = Music_Data_1 Note
                  | Music_Data_4 Direction
                  | Music_Data_9 Sound
                   ...

sortOutMusicData :: [Music_Data_] -> ([Note],[Direction],[Sound])

_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners




More information about the Beginners mailing list