Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding the Effect Monad. Erroneous example #604

Closed
JohnGurin opened this issue Jan 9, 2023 · 1 comment · Fixed by #619
Closed

Understanding the Effect Monad. Erroneous example #604

JohnGurin opened this issue Jan 9, 2023 · 1 comment · Fixed by #619
Labels
bug Something isn't working Hello-World Something related to the Hello World folder in this repo

Comments

@JohnGurin
Copy link

JohnGurin commented Jan 9, 2023

Section:
  Hello-World

Issue Type:
  Bug

Folder/File(s):
  - Hello-World/Effect-and-Aff/src/Effect/Native-Side-Effects-via-Effect.md

data Unit = Unit
unit :: Unit
unit = Unit

type PendingComputation a = (Unit -> a)
data Effect a = Box (PendingComputation a -> a)

unsafePerformEffect :: {- forall a. -} Effect a -> a
unsafePerformEffect (Box pendingComputation) = pendingComputation unit
--                                                                ^^^^
{-
 Could not match type

    Unit

  with type

    Unit -> a0
-}

source

try.purescript.org

As a suggestion

import Prelude

unsafePerformEffect :: forall a. Semiring a => Effect a -> a
unsafePerformEffect (Box pendingComputation) = pendingComputation (\_ -> one)
@JordanMartinez
Copy link
Owner

The issue is here:

type PendingComputation a = (Unit -> a)
 -- expands to    Box (Unit -> a -> a)
-data Effect a = Box (PendingComputation a -> a)
 -- expands to    Box (Unit -> a)
+data Effect a = Box (PendingComputation a)

@JordanMartinez JordanMartinez added bug Something isn't working Hello-World Something related to the Hello World folder in this repo labels Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Hello-World Something related to the Hello World folder in this repo
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants