0
votes

I'm trying to build a simple Purescript app, and I cannot figure out why I keep getting a typeclass instance error.

Specifically, inside of my Component I am defining the eval function to operate on my query algebra. In the process, I just log something to the console for fun.

type AppEffects eff = (HalogenEffects (console :: CONSOLE | eff))

data Query a = DoSomething a

eval :: Query ~> H.ComponentDSL State Query (Aff (AppEffects eff))
eval (DoSomething a) = do
    liftEff $ log "print me out!"
    -- do some stuff with the action
    pure next

When I run this, the compiler shouts:

No type class instance was found for

    Control.Monad.Eff.Class.MonadEff ( "console" :: CONSOLE         
                                     | t0                           
                                     )                              
                                     (Free                          
                                        (HalogenFP EventSource      
                                           { "someState" :: String  
                                           }                        
                                           Query                    
                                           (Aff                     
                                              ( "avar" :: AVAR      
                                              , "err" :: EXCEPTION  
                                              , "dom" :: DOM        
                                              , "console" :: CONSOLE
                                              | eff1                
                                              )                     
                                           )                        
                                        )                           
                                     )                              

The instance head contains unknown type variables. Consider adding a type annotation.

So I specified a type:

tryPrint :: Eff (console :: CONSOLE | eff) Unit
tryPrint = log "print me out!"

However, the compiler still tells me I need to implement an instance for the MonadEff typeclass. I don't really understand this error. Could anyone point me in the right direction?

1

1 Answers

2
votes

There is no MonadEff instance for Free, so you cannot use liftEff in ComponentDSL, as it is a synonym for a Free.

This is changing in the next Halogen release, and ComponentDSL will have a MonadEff instance. For the currently released version (v0.12.0) the solution is to use the fromEff function instead, which is mentioned in the "Non-state effects" section of the guide.