unsafe-perform-io Questions

6

Solved

What would be the best way to do this? unsafePerformIO? Template Haskell? Something else? I have never used either of those so I don't know many of the details of using them. Note that the program...
Pricecutting asked 6/7, 2013 at 6:3

1

It's widely understood that unsafePerformIO is not type safe. This is typically demonstrated by using it to implement unsafeCoerce: box :: IORef a box = unsafePerformIO (newIORef undefined) {-# NOI...
Flax asked 9/7, 2021 at 20:57

1

Solved

I was wandering in the Restricted Section of the Haskell Library and found these two vile spells: {- System.IO.Unsafe -} unsafeDupablePerformIO :: IO a -> a unsafeDupablePerformIO (IO m) = case ...
Hectograph asked 3/4, 2020 at 22:14

5

Solved

I often find this pattern in Haskell code: options :: MVar OptionRecord options = unsafePerformIO $ newEmptyMVar ... doSomething :: Foo -> Bar doSomething = unsafePerformIO $ do opt <- re...

8

Solved

Haskell is generally referenced as an example of a purely functional language. How can this be justified given the existence of System.IO.Unsafe.unsafePerformIO ? Edit: I thought with "purely func...

2

Solved

I am creating a Haskell application that generates a random number on an infinite loop (only when requested by a client). However, I should only use pure functions for that purpose. Is it safe to w...
Greenlaw asked 25/4, 2013 at 6:54

1

Solved

In this pseudocode block: atomically $ do if valueInLocalStorage key then readValueFromLocalStorage key else do value <- unsafeIOToSTM $ fetchValueFromDatabase key writeValueToLocalStorage ...
Innumerable asked 7/12, 2015 at 10:1

2

Solved

I'm creating an FFI module to a library in C which wants a 1-time, non-reentrant function to be called before anything else is. This call is idempotent, but stateful, so I could just call it in eve...
Disunity asked 3/1, 2013 at 18:46

4

Solved

To get acquainted with unsafePerformIO (how to use it and when to use it), I've implemented a module for generating unique values. Here's what I have: module Unique (newUnique) where import Data...
Perishable asked 15/10, 2013 at 0:55

2

Solved

I have been reading about unsafePerformIO lately, and I would like to ask you something. I'm OK with the fact that a real language should be able to interact with the external environment, so unsaf...
Chiou asked 4/4, 2012 at 22:36

2

Solved

I have a data type which contains an IORef as an important element. This means there is not a clean way to make it a member of the show type class. This is not too bad as I have a print function in...
Cleanshaven asked 30/11, 2011 at 20:10

2

Solved

I am trying to get a Haskell function to show whenever it is applied by adding a call to "putStrLn": isPrime2 1 = False isPrime2 n = do putStrLn n null (filter (==0) (map (mod n) (filter isPrim...
Birkett asked 4/10, 2011 at 15:15

3

Solved

I wrote a function in haskell that takes a few parameters like Word32, String (ignore currying) and outputs IO Word32. Now, this is a function in the true sense: for the same inputs, the output wil...

3

Solved

I found some sample code, and changed it a little counter = unsafePerform $ newIORef 0 newNode _ = unsafePerformIO $ do i <- readIORef counter writeIORef counter (i+1) return i Which ret...
Leo asked 16/12, 2010 at 14:19

5

Solved

There has been some talk at work about making it a department-wide policy of prohibiting the use of unsafePerformIO and its ilk. Personally, I don't really mind as I've always maintained that if I ...
Bish asked 8/10, 2010 at 18:16
1

© 2022 - 2024 — McMap. All rights reserved.