[Yhc] Help me for haskel problem please

Neil Mitchell ndmitchell at gmail.com
Mon Dec 6 07:49:30 CET 2010


Hi,

For homework help I suggest you read
http://haskell.org/haskellwiki/Homework_help and follow the links
listed there.

Thanks, Neil

2010/12/5 Suresh <vai.csse at gmail.com>:
> Dear Sir,
>
>       My be this question will be funny for you but I am new in Haskel and
> got only few lection and now I have to solve the question as test. Please
> let me know about suitable api for this question. We have wrong code and
> there is some test. Have to find out needed or suitable api and using these
> we have to pass all the test. But still I am so poor on Haskel. Please give
> me your good idea and material for this question. IF possible please give
> some example to solve this problem.
>
> module Grammar where
>
> import Data.Set (Set)
> import qualified Data.Set as Set
> import Prelude hiding (Int)
>
> import Test.HUnit
>
> data Term = Int Integer
>           | Atom String
>           | Var String
>           | Pair (Term, Term)
>           | Tuple [Term]
>
> data Expr = Term Term
>           | Fun [Term] [Expr]
>           | Apply Expr [Expr]
>           | Assign Term Expr
>
> boundVariables :: Expr -> Set String
> boundVariables _ = Set.empty
> fromList:: Map X Y -> [(X, Y)]
>
> freeVariables :: Expr -> Set String
> freeVariables _ = Set.empty
>
> tests =
>     let bv = boundVariables
>         fv = freeVariables
>         -- e0 := 'fun () -> ok end'
>         e0 = Fun [] [Term (Atom "ok")]
>         -- e1 := 'foo'
>         e1 = Term (Atom "foo")
>         -- e2 := 'fun (X, Y) -> F(X) end'
>         e2 = Fun [Var "X", Var "Y"]
>                  [Apply (Term (Var "F")) [Term (Var "X")]]
>         -- e3 := 'fun (true) -> F = fun (X) -> Mul(X, X) end, Add(F(X), 10)
> end'
>         e3 = Fun [Atom "true"] [
>                  Assign (Var "F")
>                         (Fun [Var "X"] [
>                              Apply (Term (Var "Mul")) [
>                                  Term (Var "X"),
>                                  Term (Var "X")
>                              ]
>                          ]),
>                  Apply (Term (Var "Add")) [
>                      Apply (Term (Var "F")) [
>                          Term (Var "X")
>                      ],
>                      Term (Int 10)
>                  ]
>              ]
>         -- e4 := 'fun () -> F(X), F = G end'
>         e4 = Fun [] [
>                  Apply (Term (Var "F")) [
>                      Term (Var "X")
>                  ],
>                  Assign (Var "F") (Term (Var "G"))
>              ]
>         -- e5 := 'fun () -> F = G, F(X) end'
>         e5 = Fun [] [
>                  Assign (Var "F") (Term (Var "G")),
>                  Apply (Term (Var "F")) [
>                      Term (Var "X")
>                  ]
>              ] in
>     runTestTT (test [
>           bv e1 ~=? Set.empty
>         , fv e1 ~=? Set.empty
>         , bv e2 ~=? Set.fromList ["X", "Y"]
>         , fv e2 ~=? Set.fromList ["F"]
>         , bv e3 ~=? Set.fromList ["X", "F"]
>         , fv e3 ~=? Set.fromList ["Mul", "Add", "X"]
>         , bv e4 ~=? Set.fromList ["F"]
>         , fv e4 ~=? Set.fromList ["F", "G", "X"]
>         , bv e5 ~=? Set.fromList ["F"]
>         , fv e5 ~=? Set.fromList ["G", "X"]
>     ])
>
>
>
>
> Best regards
> Suresh


More information about the Yhc mailing list