Questions tagged [io-monad]

Monadic interface to IO in pure functional languages, especially Haskell.

Monadic interface to IO in pure functional languages, especially Haskell.

194 questions
0
votes
1 answer

Monad transformers with IO and Maybe

I am trying to stack up IO and Maybe monads but either I don't understand monad transformers well enough or this is not possible using transformers. Can some one help me understand this? f :: String -> Maybe String main :: IO () main = do input…
Bilentor
  • 486
  • 1
  • 5
  • 13
0
votes
3 answers

Is h a handle or a lambda function (or both)?

I am looking at a simple IO program from the Haskell Wikibook. The construction presented on that page works just fine, but I'm trying to understand "how". The writeChar function below takes a filepath (as a string) and a character, and it writes…
mttpgn
  • 327
  • 6
  • 17
0
votes
2 answers

parMapN that finishes even when one program encounters an error

Using parMapN, multiple IOs can be executed in parallel, like this: import cats.implicits._ import cats.effect.{ContextShift, IO} import scala.concurrent.ExecutionContext implicit val cs: ContextShift[IO] =…
Florian Baierl
  • 2,378
  • 3
  • 25
  • 50
0
votes
1 answer

How do I load a GIF-image from computer in Haskell?

I want to have a GIF-image looping in the background of a game (For example with Gloss Juicy or module Codec.Picture.Gif) Managed to work with a BMP image like this: image :: IO Picture image = loadBMP "image.bmp" But now I want to do the same…
blobfish
  • 25
  • 3
0
votes
1 answer

Purpose of re-boxing pure value for GHCI

Can someone explain to me why when using ghci I have to "re-box" the value returned by a monad? listAction=listDirectory "D:\\" lenAction=listAction>>=length Error: Couldn't match type `Int' with `IO b0' Expected type: [FilePath] -> IO…
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152
0
votes
1 answer

Passing a randomly generated list as a parameter in Haskell

I am new to Haskell and really having trouble with the whole IO thing. I am trying to find out how long it takes to traverse a list in haskell. I wanted to generate a list of random numbers and pass it as a parameter to a function so that I can…
AR17
  • 39
  • 4
0
votes
1 answer

Control Monad (when or the likes) and non IO() return types

I am trying to use the "when" function in my program because I want to have an action preformed if something is true and not if its not true. I could also accomplish the same thing by using the Maybe monad but that will clutter the rest of my…
John Brown
  • 13
  • 5
0
votes
1 answer

Haskell: Turtle: Managing Shell type

This a working snippet: import Turtle ... groom :: FilePath -> IO () groom src = do view (ls src) ... I can see a list of paths on the console. Actually I'd like to have something like [FilePath] for use, e.g.: treeCount :: FilePath ->…
Alexey Orlov
  • 2,412
  • 3
  • 27
  • 46
0
votes
1 answer

How to display Response from an HTTP GET Request in front-end using Scotty?

I'm trying out Scotty for the first time and I can't seem to get past making my GET request. The Response is returned as type IO (Response bytestring-0.10.8.1:Data.ByteString.Lazy.Internal.ByteString) I know I need to convert it to a type that…
0
votes
0 answers

Difference in how IO works in FP vs Non FP languages

Let's take the simple case here (pseudo code) def readnonfp(): String = { nonMonadicIO.readFile("somefile") } def readfp(): IO[String] = { monadicIO.readFile("somefile") } Now this will be maybe composed like…
ffff
  • 2,853
  • 1
  • 25
  • 44
0
votes
1 answer

IO action nested in other monads not executing

I have a foobar :: IO (ParseResult [(String,String)]) ParseResult is a monad defined here: https://hackage.haskell.org/package/haskell-src-exts-1.13.5/docs/Language-Haskell-Exts-Parser.html#t:ParseResult I want to take those strings and write them…
LambdaScientist
  • 435
  • 2
  • 13
0
votes
1 answer

Example of while loop in Haskell using monads

I want to write a loop in haskell using monads but I am having a hard time understanding the concept. Could someone provide me with one simple example of a while loop while some conditions is satisfied that involves IO action? I don't want an…
domoremath
  • 555
  • 2
  • 8
  • 17
0
votes
1 answer

Haskell Errors Binding a CSV File to a Handle

So I was writing a small toybox of utility functions for CSV files and throughout testing the functions I'd been binding the file by hand with table' <- parseCSVFromFile filepath but (from Text.CSV) parseCSVFromFile :: FilePath -> IO (Either…
Tshimanga
  • 845
  • 6
  • 16
0
votes
1 answer

Haskell & Scrypt: How to get the encrypted hash

*Sorry for the basic question, just started learning Haskell. I am trying to write a function that will get a string and return an encrypted hash. What I have come up with for the moment is: encrypt :: ByteString -> ByteString encrypt = do x <-…
user6307701
0
votes
1 answer

Combining and splitting assignment in Haskell IO do block

I /think/ I have a similar misunderstanding of the language in two places involving how variable assignment works in do blocks, involving the IO monad. Could you help me understand (1) is it the same misunderstanding, (2) how to clear it up (in an…
Mittenchops
  • 18,633
  • 33
  • 128
  • 246
1 2 3
12
13