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! :) )
___
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
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
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
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
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
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
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:
>
--- 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
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
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
> 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
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
__
13 matches
Mail list logo