Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8763827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:52:31+00:00 2026-06-13T15:52:31+00:00

Heinrich Apfelmus generously chimed in on this problem. I had considered using accumB as

  • 0

Heinrich Apfelmus generously chimed in on this problem. I had considered using accumB as a solution, but thought there would be a type error. After trying his suggestion anyway, I did recieve a type error.

let bGameState :: Behavior t GameState
    bGameState = accumB initialGS $ updateGS <$ eInput

yields the error

 Couldn't match expected type `GameState'
             with actual type `PlayerCommand'
 Expected type: GameState -> GameState
   Actual type: PlayerCommand -> GameState -> GameState
 In the first argument of `(<$)', namely `updateGS'
 In the second argument of `($)', namely `updateGS <$ eInput'

So I studied (<$), and messed around with partial application. Looked at his suggested examples. The more I did this, the more I thought the above code should work, and I am baffled as to why it doesn’t.

This is what I think should be happening:

since (<$) is of type (<$) :: a -> f b -> f a

and updateGS is of type updateGS :: PlayerCommand -> GameState -> GameState

and eInput is of type Event t PlayerCommand

then should not updateGS <$ eInput yield

Event t (GameState -> GameState) ?

My reasoning is flawed somewhere, could someone point out where?

Update: when I tried using (<$>) I recieved the following error

outline.hs:158:21:

Could not deduce (t ~ t1)
from the context (Frameworks t)
  bound by a type expected by the context:
             Frameworks t => Moment t ()
  at outline.hs:(153,42)-(159,93)
  `t' is a rigid type variable bound by
      a type expected by the context: Frameworks t => Moment t ()
      at outline.hs:153:42
  `t1' is a rigid type variable bound by
       the type signature for bGameState :: Behavior t1 GameState
       at outline.hs:158:8
Expected type: Behavior t1 GameState
  Actual type: Behavior t GameState
In the expression: accumB initialGS $ updateGS <$> eInput
In an equation for `bGameState':
    bGameState = accumB initialGS $ updateGS <$> eInput

for reference, here is the whole function

makeNetworkDescription :: AddHandler PlayerCommand -> IO EventNetwork
makeNetworkDescription addCommandEvent = compile $ do
   eInput <- fromAddHandler addCommandEvent
   let bCommand = stepper Null eInput
   eCommandChanged <- changes bCommand
   let bGameState :: Behavior t GameState
       bGameState = accumB initialGS $ updateGS <$> eInput
   reactimate $ (\n -> appendFile "output.txt" ("Command is " ++ show n)) <$>    
   eCommandChanged
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:52:32+00:00Added an answer on June 13, 2026 at 3:52 pm

    What’s wrong with the code

    You should be using <$>, not <$.

    • <$>, a.k.a. fmap applies a function to the value of the right hand side events, which is what you’re trying to do in this case.
    • <$ replaces the value of the right hand side events with the left hand side, giving you an event which occurs at the same time as the original, but which always contains the same value.

      Note: x <$ e is the same as const x <$> e.

    Why your reasoning is wrong

    We’re trying to determine the type of updateGS <$ eInput where the types of the subterms are:

    (<$)     :: a -> f b -> f a
    updateGS :: PlayerCommand -> GameState -> GameState
    eInput   :: Event t PlayerCommand
    

    Now think: what types must a, b and f be instantiated to?

    1. Since updateGS is the first argument to <$ which has type a, we must have

      a ~ PlayerCommand -> GameState -> GameState
      
    2. Similarly, eInput is the second argument to <$ which has type f b, so

      f b ~ Event t PlayerCommand
      

      Type application associates to the left, so Event t PlayerCommand is the same as (Event t) PlayerCommand. We can therefore determine that

      f ~ Event t
      b ~ PlayerCommand
      
    3. Putting together the type of the result, f a, we see that

      f a ~ Event t (PlayerCommand -> GameState -> GameState)     
      

    Therefore, updateGS <$ eInput :: Event t (PlayerCommand -> GameState -> GameState), which explains the type error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the operational monad by Heinrich Apfelmus. I'd like to parameterize the interpreter
I'm currently trying to get to know FRP through Heinrich Apfelmus' reactive-banana , which
I am using IBM Rational Software Architect for creating a UML Model and then
I am making heavy use of Springs XML Configuration for Java Beans. Is there
Background : 19th-century German archeologist Heinrich Schliemann was of course famous for his successful
in a Spring MVC Controller I would like to start a thread that continues
programming in C with the X11 library, is there a way to get notified
I have a process that continuously needs to write information. Furthermore, there is a
I have a problem with my spring controller/request mapping struture. In web.xml I have
I'm new to rails application. I got connection with mongodb using mongoid. I generated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.