sdiehl / write-you-a-haskell

Building a modern functional compiler from first principles. (http://dev.stephendiehl.com/fun/)
MIT License
3.34k stars 256 forks source link

Small-Step Semantics type error #30

Closed MasseGuillaume closed 9 years ago

MasseGuillaume commented 9 years ago

I dont think this typechecks

https://github.com/sdiehl/write-you-a-haskell/blob/master/004_type_systems.md#small-step-semantics

-- Evaluate a single step.
eval1 :: Expr -> Maybe Expr
eval1 expr = case expr of
  Succ t                    -> Succ <$> (eval1 t)
  Pred Zero                 -> Just Zero
  Pred (Succ t) | isNum t   -> Just t
  Pred t                    -> Pred <$> (eval1 t)
  IsZero Zero               -> Just Tr
  IsZero (Succ t) | isNum t -> Just Fl
  IsZero t                  -> IsZero <$> (eval1 t)
  If Tr  c _                -> Just c
  If Fl _ a                 -> Just a
  If t c a                  -> (\t' -> If t' c a) <$> eval1 t
  _                         -> Nothing
sdiehl commented 9 years ago

Can you elaborate on the problem? The code included for chapter4 type checks on my build.

MasseGuillaume commented 9 years ago

oh I did not see the applicative.

Succ <$> (eval1 t) is a Maybe Expr