2016-07-10 2 views
2

나는 간단한 해커를 만들려고 노력하고있다. 간단한 putStrLn과 getLine을 만들려고 노력했다. (이것이 최고의 해결책인지는 모른다. 문제가 있건 없건간에, 나는 상당히 새로운 것입니다.)작은 트위터 클라이언트를위한 하스켈 IO cli 메뉴

나는 이런 식으로 뭔가를하고 싶어하지만 출력 유형이 너무 거 대규모 오류주고 다른 :

Main.hs:86:25: error: 
    Couldn't match type ‘Either String DM’ with ‘()’ 
    Expected type: IO() 
     Actual type: IO (Either String DM) 
:

main:: IO() 
main = do 
    putStrLn "1)Tweet\n 2)Timeline\n 3)DM\n 4)Inbox\n" 
    numero <- getLine 
    if(numero == 1) 
     then do 
      frase <- getLine 
      tweet frase 
     else 
      if(numero == 2) 
       then do 
        frase <- getLine 
        timeline frase 
      else 
       if(numero == 3) 
        then do 
         frase <- getLine 
         nome <- getLine 
         dm frase nome 
        else 
        if(numero == 4) 
          then 
           inbox 
          else do 
            PutstrLn "Invalido" 


tweet :: String -> IO (Either String Tweet) 

timeline :: String -> IO (Either String [Tweet]) 

dm :: String -> String -> IO(Either String DM) 

inbox :: IO(Either String [DM]) 

을 그리고 같은 내가 그 거 위의 설명은 당신에게 같은 오류를 제공

및 :

Main.hs:75:11: error: 
• Couldn't match type ‘Either String Tweet’ with ‘()’ 
    Expected type: IO() 
    Actual type: IO (Either String Tweet) 

이 특정 pr을 해결할 사람이 있다면 oblem 매우 감사하겠습니다.

+0

모든 관련 코드 및 오류 메시지를 게시하십시오. 귀하의 게시물이 [최소, 완전하고 검증 가능한 예] (http://stackoverflow.com/help/mcve)를 제공하지 않으면 귀하를 도울 수 없습니다. – Mephy

+0

@Mephy는 몇 가지 예제를 추가했습니다. –

+0

질문에 오타가 있습니다. 'PutstLn'은'putStrLn'이어야합니다. – Cirdec

답변

2

당신의 IO 작업이 inbox :: IO(Either String [DM]) 같은 값을 반환하지만 그것이 IO() 당신이 반환 값을 무시하고 유형 IO()이있는 return() 그것을 따를 수 있어야 곳을 사용합니다.

if(numero == 1) 
     then do 
      frase <- getLine 
      tweet frase 
      return() 
     else 
      ... 

제외 : 당신이 case expression 대신 중첩 된 if ... then ... else의의를 사용하여이에 대한 들여 쓰기를 단순화 할 수 있습니다.

main:: IO() 
main = do 
    putStrLn "1)Tweet\n 2)Timeline\n 3)DM\n 4)Inbox\n" 
    numero <- readLn 
    case numero of 
     1 -> do 
      frase <- getLine 
      tweet frase 
      return() 
     2 -> do 
      frase <- getLine 
      timeline frase 
      return() 
     3 -> do 
      frase <- getLine 
      nome <- getLine 
      dm frase nome 
      return() 
     4 -> do 
      inbox 
      return() 
     otherwise -> do 
      putStrLn "Invalido" 

는 또한 readLn :: Read a => IO agetLine :: IO String를 교체했습니다.

+0

감사합니다. 잘 설명해 드리겠습니다. 10 점 만점에 10 점 –