preprocessing printf/regex strings (like ocaml)

Sebastien Carlier sebc@wise-language.org
Sun, 12 May 2002 12:50:24 +0200


--Apple-Mail-1--56247867
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed


>>> the python string notation (str % tuple) would fit really well too...
>>>     putStrLn "hello %s, you got %d right" % ("oliver", 5)
>>
>> Might be nice.
>
> What would be the type of putStrLn then?

The type of putStrLn would remain unchanged.

The idea would be to let the compiler translate the string
	"hello %s, you got %d right"
into the function
	(\ (p1, p2) -> "hello " ++ p1 ++ ", you got " ++ show p2 ++ " right")
so that the type system can do its work.  Then the % above is only an
application.
There is of course no need for the tuple;  a curried function would
probably be more convenient.

You may ask, how would the compiler know that this "string" is meant
to be a function ?
I think it would be nice to have a similar syntax for matching strings
and for building strings.  Following David's example:

q = case x of
         /"^$" -> "Empty Line."
         /"^(foo@\d+)" -> /"%s hello!" foo
         /"confusion (foo@?) (bar@*)" -> /"foo is %s And bar is %s" foo 
bar
         /"(a@*)" -> error (/"Sorry: I don't know what to do with %s" a)

--
"Choose Again."

--Apple-Mail-1--56247867
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII


<excerpt><excerpt><excerpt>the python string notation (str % tuple)
would fit really well too...

    putStrLn "hello %s, you got %d right" % ("oliver", 5)

</excerpt>

Might be nice.

</excerpt>

What would be the type of putStrLn then?

</excerpt>

The type of putStrLn would remain unchanged.


The idea would be to let the compiler translate the string

	<color><param>5454,0000,0000</param>"hello %s, you got %d right"

</color>into the function

	(\ (p1, p2) -> "hello " ++ p1 ++ ", you got " ++ show p2 ++ " right")

so that the type system can do its work.  Then the % above is only an

application.

There is of course no need for the tuple;  a curried function would

probably be more convenient.


You may ask, how would the compiler know that this "string" is meant

to be a function ?

I think it would be nice to have a similar syntax for matching strings

and for building strings.  Following David's example:


q = case x of

        /"^$" -> "Empty Line."

        /"^(foo@\d+)" -> /"%s hello!" foo

        /"confusion (foo@?) (bar@*)" -> /"foo is %s And bar is %s" foo
bar

        /"(a@*)" -> error (/"Sorry: I don't know what to do with %s" a)


-- 

"Choose Again."


--Apple-Mail-1--56247867--