Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

### Values

modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) { }
modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit

newRef :: forall s r. s -> Eff (ref :: Ref | r) (RefVal s)

readRef :: forall s r. RefVal s -> Eff (ref :: Ref | r) s

writeRef :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) { }
writeRef :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) Unit


## Module Control.Monad.Eff.Ref.Unsafe
Expand Down
4 changes: 2 additions & 2 deletions src/Control/Monad/Eff/Ref.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ foreign import modifyRef
\ return {};\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One very slight issue here: these various FFI calls return {}, which doesn't have the runtime representation of the type Unit, so pattern matching on the result, for example, while not necessarily useful, could result in a runtime error. To be super safe, these things should probably return Prelude.unit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did have a slight worry about that. I checked the generated code for Eq, Ord, things like that and none of them attempt to read from the value so I think at least in PS code it should be fine. I also figure this'll be fixed when we get newtypes working.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so this is a problem actually when compiled with no optimizations. One fix is to not pattern match in the Prelude definitions, just use _ instead of (Unit {}). I've updated the Prelude in ps-in-ps to have the definitions this way so it's not broken in psci.

\ };\
\ };\
\}" :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) {}
\}" :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit

foreign import writeRef
"function writeRef(ref) {\
Expand All @@ -39,4 +39,4 @@ foreign import writeRef
\ return {};\
\ };\
\ };\
\}" :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) {}
\}" :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) Unit