Skip to content

Commit 7016688

Browse files
committed
Manually define Monad Expression
1 parent a74247a commit 7016688

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

src/Language/Elm/Expression.hs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
{-# language ScopedTypeVariables #-}
88
{-# language StandaloneDeriving #-}
99
{-# language TemplateHaskell #-}
10+
{-# language TupleSections #-}
1011
module Language.Elm.Expression where
1112

1213
import Bound
@@ -44,8 +45,44 @@ instance Applicative Expression where
4445
(<*>) = ap
4546

4647
instance Monad Expression where
47-
(>>=) =
48-
flip $ bind Global
48+
expression >>= f =
49+
case expression of
50+
Var v ->
51+
f v
52+
53+
Global g ->
54+
Global g
55+
56+
App g x ->
57+
App (g >>= f) (x >>= f)
58+
59+
Let e s ->
60+
Let (e >>= f) (s >>>= f)
61+
62+
Lam e ->
63+
Lam (e >>>= f)
64+
65+
Record fields ->
66+
Record (map (fmap (>>= f)) fields)
67+
68+
Proj fieldName ->
69+
Proj fieldName
70+
71+
Case e patterns ->
72+
Case (e >>= f) (map (fmap (>>>= f)) patterns)
73+
74+
List es ->
75+
List (map (>>= f) es)
76+
77+
String text ->
78+
String text
79+
80+
Int integer ->
81+
Int integer
82+
83+
Float double ->
84+
Float double
85+
4986

5087
bind :: forall v v'. (Name.Qualified -> Expression v') -> (v -> Expression v') -> Expression v -> Expression v'
5188
bind global var expression =

0 commit comments

Comments
 (0)