[Haskell-cafe] Re: Haskell Helper
I was able to parse function definition, but function call still is a problem, -- View this message in context: http://haskell.1045720.n5.nabble.com/Haskell-Helper-tp3093854p3205482.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Haskell Helper
On 4 October 2010 23:54, c8h10n4o2 wrote: > By the way, there is a parser that returns [String] for my case? > If you are trying to parse strings (of alphaNum's) separated by commas, you can use "many alphaNum" (or "many1 alphaNum" depending on what you want) instead of simply using alphaNum. The type of the complete parser will then be Parser [String]. alphaNum :: Parser Char alphaNums :: Parser String alphaNums = many alphaNum alphaNums1 :: Parser String alphaNums1 = many1 alphaNum Ozgur ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Helper
I read the parsec documentation and saw my mistake. By the way, there is a parser that returns [String] for my case? -- View this message in context: http://haskell.1045720.n5.nabble.com/Haskell-Helper-tp3093854p3198573.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Haskell Helper
On 4 October 2010 23:10, c8h10n4o2 wrote: > And why > b <- between (char ',') (char '=') (sepBy alphaNum (char ',') ) > does not return [String] ? > alphaNum :: Parser Char sepBy :: Parser a -> Parser sep -> Parser [a] sepBy alphaNum sepP :: Parser [Char] or Parser String but not Parser [String] between :: Parser open -> Parser close -> Parser a -> Parser a between openP closeP (sepBy alphaNum sepP) :: Parser String Hope this helps, Ozgur ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Helper
And why b <- between (char ',') (char '=') (sepBy alphaNum (char ',') ) does not return [String] ? -- View this message in context: http://haskell.1045720.n5.nabble.com/Haskell-Helper-tp3093854p3198511.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Helper
Ben Franksen wrote: > The type checker tells you that you are using the same Map with different > key types: at 52:17-19 the key has type [Hai], whereas at 47:16-18 it has > type Hai. > > The latter is in your Func case: s/latter/former/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Helper
c8h10n4o2 wrote: > The problem is there. A function in Hai would be function-name, > arg1,argn=body. > Func stores function name,arguments and body as Strings(I was thinking to > put Func String String String). > The parser func that I wrote so far try to parse a function definition, > not a function call. > But when I try to store the function on my Map I get a error with somthing > called 'functional dependencies'(which I don't know what is). You mean: hai1.hs:41:6: Couldn't match expected type `Hai' against inferred type `[Hai]' Expected type: Map.Map Hai Hai Inferred type: Map.Map [Hai] Hai When using functional dependencies to combine MonadState (Map.Map [Hai] Hai) m, arising from a use of `get' at hai1.hs:52:17-19 MonadState (Map.Map Hai Hai) m, arising from a use of `get' at hai1.hs:47:16-18 When generalising the type(s) for `w' The type checker tells you that you are using the same Map with different key types: at 52:17-19 the key has type [Hai], whereas at 47:16-18 it has type Hai. The latter is in your Func case: e <-return $ Map.insert (a :[b]) c d where you use a :[b] which is the same as [a,b] for the key. Everywhere else, the key has type Hai. This in itself is questionable: do you really want to use arbitrary expressions as keys? Usually one would have a Map String Hai representing a map from variable (or function) names to expressions. For functions you then want data Hai = ... | Func [String] Hai | ... so that Func args body represents the (anonymous) function with the formal arguments args and the resulting expression body . The function gets a name by inserting it into the variable map. This means that a definition function-name,arg1,...,argn=body actually defines a variable named "function-name" which, when it gets looked up in the environment, yields the value Func [arg1,...,argn] body . Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Helper
The problem is there. A function in Hai would be function-name, arg1,argn=body. Func stores function name,arguments and body as Strings(I was thinking to put Func String String String). The parser func that I wrote so far try to parse a function definition, not a function call. But when I try to store the function on my Map I get a error with somthing called 'functional dependencies'(which I don't know what is). -- View this message in context: http://haskell.1045720.n5.nabble.com/Haskell-Helper-tp3093854p3117672.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Helper
c8h10n4o2 wrote: > No, it is not secret. I'm having trouble to define functions. Take a look > at my code(please be gentle) > http://haskell.1045720.n5.nabble.com/file/n3100036/hai1.hs hai1.hs Can you explain in a few words what the Func constructor should represent why it has three arguments? I ask because I am not sure whether it represents function definition or function call. Maybe yuou can give a small example for a function definition as well as a function application (call) in your Hai language. Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Helper
No, it is not secret. I'm having trouble to define functions. Take a look at my code(please be gentle) http://haskell.1045720.n5.nabble.com/file/n3100036/hai1.hs hai1.hs -- View this message in context: http://haskell.1045720.n5.nabble.com/Haskell-Helper-tp3093854p3100036.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe