Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-16 Thread Albert Lai
Huong Nguyen <[EMAIL PROTECTED]> writes: > newtype Parser a = Parser(String -> [(a, String)]) [...] > parse :: Parser a -> String -> [(a, String)] > parse p cs = p cs > \end{code} Try this instead: parse (Parser p) cs = p cs (You forgot to deconstruct! :) ) ___

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-16 Thread Huong Nguyen
Thanks all of your for your time and your interesting examples. Now I can see that my problem is parsing a String. I am new in Haskell, so, I start to study parsing and how to create a parser from beginning. I start with an example from the book as follows: %The parser item fails if the input is e

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-14 Thread Ralf Hinze
Hi Huong, attached you find a small program for parsing values of various (data) types. It uses a generalized algebraic data type for representing types and a universal data type for representing values. The parser itself is rather simple-minded: it builds on Haskell's "ReadS" type. I don't know

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-14 Thread robert dockins
So this is essentially a parsing problem. You want a user to be able input a string and have it interpreted as an appropriate data value. I think you may want to look at the Parsec library (http://www.cs.uu.nl/~daan/parsec.html). I don't think the direction you are heading will get the resul

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-14 Thread Sebastian Sylvan
On 10/13/05, Huong Nguyen <[EMAIL PROTECTED]> wrote: > Hi all, > > I want to write a small functionto test whether an input is a String or not. > For example, > > isString::(Show a) =>a ->Bool > This function will return True if the input is a string and return False if > not > > Any of you have id

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-14 Thread Ben Rudiak-Gould
Cale Gibbard wrote: As an example of this sort of thing, I know that there are only 4 values of type a -> Bool (without the class context). They are the constant functions (\x -> True), (\x -> False), and two kinds of failure (\x -> _|_), and _|_, where _|_ is pronounced "bottom" and represents s

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-14 Thread John Meacham
On Fri, Oct 14, 2005 at 03:17:12AM -0400, Cale Gibbard wrote: > Right, forgot about seq there, but the point still holds that there > are a very limited number of functions of that type, and in > particular, the functions can't decide what to do based on the type > parameter 'a'. > actually, witho

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-14 Thread Cale Gibbard
Right, forgot about seq there, but the point still holds that there are a very limited number of functions of that type, and in particular, the functions can't decide what to do based on the type parameter 'a'. - Cale On 14 Oct 2005 05:49:27 -, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-13 Thread voigt . 16734551
--- Cale Gibbard <[EMAIL PROTECTED] wrote: > As an example of this sort of thing, I know that there are only 4 > values of type a -> Bool (without the class context). They are the > constant functions (\x -> True), (\x -> False), and two kinds of > failure (\x -> _|_), and _|_, where _|_ is pronoun

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-13 Thread robert dockins
In GHC you can do this: > import Data.Typeable > isString :: (Typeable a) => a -> Bool > isString x = typeOf x == typeOf (undefined::String) Why do you want this? It's not the kind of operation one does very often in Haskell. Huong Nguyen wrote: Hi all, I want to write a small function

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-13 Thread Cale Gibbard
There is a way to do this using a bunch of GHC extensions, but I get the feeling that you're misinterpreting parametric polymorphism. The type (Show a) => a -> Bool means that the function isString can be implemented without caring what type a is, only knowing that it is in Show. As an example of

Re: [Haskell-cafe] Newbie question on Haskell type

2005-10-13 Thread Neil Mitchell
> isString::(Show a) =>a ->Bool > This function will return True if the input is a string and return False if > not This is not particularly nicely - you certainly can't write it as simple as the 'isString' function, and it will probably require type classes etc, quite possibly with haskell extensi

[Haskell-cafe] Newbie question on Haskell type

2005-10-13 Thread Huong Nguyen
Hi all,   I want to write a small functionto test whether an input is a String or not. For example,   isString::(Show a) =>a ->Bool This function will return True if the input is a string and return False if not   Any of you have idea about that? Thanks in advance __