fromIRCMsg :: IRCMsg -> ByteString
fromIRCMsg msg = BS.concat $ [prefix', command', params', trail', "\r\n"]
  where prefix' = case msgPrefix msg of
          Nothing -> ""
          Just (Right serv) -> ':' `cons` serv `append` " "
          Just (Left info)  -> ':' `cons` userNick info
                               `append` maybeUser
                               `append` maybeHost
                               `append` " "
            where 
              maybeUser  = maybe ""  ('!' `cons`) (userName info)
              maybeHost  = maybe "" ('@' `cons`) (userHost info)
      
        command' = msgCmd msg            
        
        paramList = msgParams msg
        params'
          | Prelude.null paramList = ""
          | otherwise = ' ' `cons` intercalate " " (msgParams msg)
      
        trail' = case msgTrail msg of
            Nothing -> ""
            Just t -> " :" `append` t
fromIRCMsg :: IRCMsg -> ByteString
fromIRCMsg msg = BS.concat $ [prefix', command', params', trail', "\r\n"]
  where prefix' = case msgPrefix msg of
          Nothing -> ""
          Just (Right serv) -> ':' `cons` serv `append` " "
          Just (Left info)  -> ':' `cons` userNick info
                               `append` maybeUser
                               `append` maybeHost
                               `append` " "
            where 
              maybeUser  = maybe ""  ('!' `cons`) (userName info)
              maybeHost  = maybe "" ('@' `cons`) (userHost info)
      
        command' = msgCmd msg            
        
        paramList = msgParams msg
        params'
          | Prelude.null paramList = ""
          | otherwise = ' ' `cons` intercalate " " (msgParams msg)
      
        trail' = case msgTrail msg of
            Nothing -> ""
            Just t -> " :" `append` t
fromIRCMsg msg = BS.concat $ [prefix', command', params', trail', "\r\n"]
  where prefix' = case msgPrefix msg of
          Nothing -> ""
          Just (Right serv) -> ':' `cons` serv `append` " "
          Just (Left info)  -> ':' `cons` userNick info
                               `append` maybeUser
                               `append` maybeHost
                               `append` " "
            where 
              maybeUser  = maybe ""  ('!' `cons`) (userName info)
              maybeHost  = maybe "" ('@' `cons`) (userHost info)
      
        command' = msgCmd msg            
        
        paramList = msgParams msg
        params'
          | Prelude.null paramList = ""
          | otherwise = ' ' `cons` intercalate " " (msgParams msg)
      
        trail' = case msgTrail msg of
            Nothing -> ""
            Just t -> " :" `append` t