couldn't match expected type ByteString with actual type IO ByteString

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

couldn't match expected type ByteString with actual type IO ByteString

Carl Petersen
Hello All,

I'm getting the following error:

/apps/workspace/hade/src/Step/ReadExcel.hs:39:23:
    Couldn't match expected type ‘L.ByteString’
                with actual type ‘IO L.ByteString’
    In the first argument of ‘IBuf’, namely ‘j’
    In the second argument of ‘sendChan’, namely ‘(IBuf j)’


when I compile the following code:

data Buf = IChan (SendPort Buf) | IBuf (L.ByteString) deriving (Show,Generic,Typeable)

instance Binary Buf

readExcel :: Process()
readExcel = do
  sendChan chan (IBuf j)
 where
    IChan chan = expect
    j = do
      r <- toTableRowsFromFile 8 "final-project.xlsx"
      let b = A.encode r
      return b

remotable ['readExcel]

Any ideas as to what I'm doing wrong?

Carl


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: couldn't match expected type ByteString with actual type IO ByteString

Mitchell Rosen
The error message is really all you need. You are passing a value of type IO ByteString to IBuf which expects a value of type ByteString.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: couldn't match expected type ByteString with actual type IO ByteString

Marc A. Ziegert
In reply to this post by Carl Petersen
hi carl,
 
i hope this seven-step program will help you with your problem.
 
1.) this is a very-very-beginner's question. (and yet you use Typeable and Generics, so this is most likely some copy-pasted code.) so be aware and know your problem: that you are not even a beginner and that you shall not trust your assumptions.
i'm sure you are not allone with your problem; there is that pseudonymous group... https://mail.haskell.org/mailman/listinfo/beginners
2.) read up about Monads&Gonads or Monads&Burritos... or maybe later, but then take your time. one day or weekend could be enough. but first know:
2b.) IO ByteString is a program snippet (input-output-operation) that produces a ByteString. it is not a ByteString itself, it is some executable program code; you need to run it and do something with its output.
3.) you did not write about any imports, so i don't know the type Process, but if Process is IO, then try this (if it doesn't work, give us more information about those types and/or libraries you did hide from us):
do
  jj<-j
  sendChan chan (IBuf jj) 
4.) you wrote "Process()" instead of "Process ()", which *looks* to many haskellers like you might misguidedly assume that it is some kind of function or method with params in those parentheses? in that case, in order to understand types, you might want to investigate and experiment with Data.Maybe, Data.List, Data.Either, and Data.Functor using ghci.
5.) now that you know that an Int is-not-an [Int] is-not-a String is-not-any IO String ... nor any Duck a Maybe Duck but Just a Duck ...  read up about Monads. then use ghci to explore Control.Monad and use the "do-notation".
6.) blog about why and how a list (that are these cute brackets "[]" called list -- and not that null-tuple "()" called unit) is a Monad
7.) congrats, now you are a beginner.
 
 
Gesendet: Donnerstag, 09. Juni 2016 um 14:07 Uhr
Von: "Carl Petersen" <[hidden email]>
An: Haskell-cafe <[hidden email]>
Betreff: [Haskell-cafe] couldn't match expected type ByteString with actual type IO ByteString
Hello All,

I'm getting the following error:

/apps/workspace/hade/src/Step/ReadExcel.hs:39:23:
    Couldn't match expected type ‘L.ByteString’
                with actual type ‘IO L.ByteString’
    In the first argument of ‘IBuf’, namely ‘j’
    In the second argument of ‘sendChan’, namely ‘(IBuf j)’


when I compile the following code:

data Buf = IChan (SendPort Buf) | IBuf (L.ByteString) deriving (Show,Generic,Typeable)

instance Binary Buf

readExcel :: Process()
readExcel = do
  sendChan chan (IBuf j)
 where
    IChan chan = expect
    j = do
      r <- toTableRowsFromFile 8 "final-project.xlsx"
      let b = A.encode r
      return b

remotable ['readExcel]

Any ideas as to what I'm doing wrong?

Carl
 
_______________________________________________ Haskell-Cafe mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe