Re: [Haskell-cafe] Desugaring of infix operators is (always?) the wrong way round

2007-09-25 Thread Sam Hughes

Brian Hulley wrote:

Dan Piponi wrote:

On 9/25/07, Brian Hulley [EMAIL PROTECTED] wrote:

..


I don't understand what you mean. For example, with the prefix 
definition of a function with multiple clauses, the function name at the 
start of each clause is already lined up since it must appear at the 
margin of the current layout block (especially if you follow the simple 
rule of always following a layout starter token by a newline rather than 
starting a new multi-line layout block in the middle of a line), whereas 
with the postfix notation you'd need to manually line up the function 
names if you wanted the same neat look.


Or you could have everything be backwards, and use an editor that right 
aligns things.


It's not so clear to me what the syntax for types should be in a 
postfix language.



Postfix, of course! So you'd write

data a Tree = Leaf | a a Tree


 data
a a Tree |
Leaf = a Tree


A postfix version could be:

   map :: (a - b) - a List - b List
   Empty _ map = Empty
   (h t PushF) f map = (h f) (t f map) PushF



   (a - b) - [a] - [b] ::  map
[] = [] _ map
x f : xs f map = (x:xs) f map


- Sam
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Noob question and sequence of operations (print then do something else)

2007-09-24 Thread Sam Hughes

John Wicket wrote:


On 9/24/07, Sam Hughes [EMAIL PROTECTED] wrote:

John Wicket wrote:

I am still in an imperative way of thinking.  In this example here; how
would I call putStrLn and then set the function with a value.  Eg:

aa :: String - IO ()
aa instr = do
  putStrLn abc
  putStrLn abc
  return 123

--- The error I am getting.

Couldn't match expected type `()' against inferred type `[Char]'
In the first argument of `return', namely `123'
In the expression: return 123
In the expression:
do putStrLn abc
   putStrLn abc
   return 123

Your type signature is wrong.  If you want an IO action whose return
value is a String, say so:

aa :: String - IO String




 Sorry, I was actually trying to use this as an example for something more
 complicated I am trying to do.  In this example, why would the 
inferred type

 be IO ()

 aa :: String - String
 aa instr = do
   putStrLn abc
   putStrLn abc
   return Az

   Couldn't match expected type `[t]' against inferred type `IO ()'
 In the expression: putStrLn abc
 In a 'do' expression: putStrLn abc
 In the expression:
 do putStrLn abc
putStrLn abc
return Az


Ah.  Because the value,  putStrLn abc,  is a value of type IO (). Your 
problem is that you're trying to do an input/output action in a pure 
function.  You'll need a function that returns a value of type 'IO 
String' (or 'IO somethingElse').  Then the do notation is used to 
construct actions, by chaining small actions together.  Here your 
compiler thinks it's trying to construct a list, because do notation can 
be used for any monad...


Note that 'return' isn't a keyword that returns from a function, it's a 
function that returns a value.  For example, in the code


foo :: IO Int
foo = do print 3
 return 5

return 5  is of type  IO Int.  That is, it's an action that 'returns' a 
value of type Int (when executed), so to speak.  ('print 3' is an action 
that 'returns' a value of type (), by the way.)


When you say you have

aa :: String - String,

you're advertising that (aa foo) is a String.  You're not advertising 
that it's an action that returns a String, because they're different 
things.  do notation isn't for doing things and returning a value, it's 
for combining actions together into one bigger action.  If you want to 
do things, you need your function to construct an action that does 
things, which means you want


aa :: String - IO String

But the function 'aa' doesn't do things, it constructs an action.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Noob question and sequence of operations (print then do something else)

2007-09-23 Thread Sam Hughes

John Wicket wrote:

I am still in an imperative way of thinking.  In this example here; how
would I call putStrLn and then set the function with a value.  Eg:

aa :: String - IO ()
aa instr = do
  putStrLn abc
  putStrLn abc
  return 123

--- The error I am getting.

Couldn't match expected type `()' against inferred type `[Char]'
In the first argument of `return', namely `123'
In the expression: return 123
In the expression:
do putStrLn abc
   putStrLn abc
   return 123


Your type signature is wrong.  If you want an IO action whose return 
value is a String, say so:


aa :: String - IO String
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How can I stop GHCi from calling show for IO actions?

2007-09-15 Thread Sam Hughes

Ryan Ingram wrote:

Prelude let inf = repeat 1
Prelude inf
[1,1,(lots of output until I press ctrl-c),Interrupted.
(I expect this to happen)
Prelude let x = inf
(no output here!)
Prelude :t x
x :: [Integer]
Prelude return inf
[1,1,(lots of output until I press ctrl-c),Interrupted.
(I also expect this to happen)
Prelude y - return inf
[1,1,(lots of output until I press ctrl-c),Interrupted.
(I do not expect this to happen here!)
Prelude :t y

interactive:1:0: Not in scope: 'y'

Is this a bug?  Why does y - return exp have different behavior
than let y = exp?  Is there a way to make GHCi not print the result
of an action but still make my variables get bound?


That's weird.

Prelude (x,y) - return $ (repeat 1, repeat 2)
Prelude Just x - return $ Just (repeat 1)
[1,1,1,...
Prelude (x,_) - return $ (repeat 1, repeat 2)
[1,1,1,...
Prelude Just (x,y) - return $ Just (repeat 1, repeat 2)
Prelude

It seems that GHCi outputs the contents of the variable you've created 
when there's only one of them.


- Sam
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IO within parser

2007-08-13 Thread Sam Hughes

Malte Milatz wrote:

Sam Hughes [EMAIL PROTECTED], Sun, 12 Aug 2007 20:12:55 -0400:
[A parser like Parsec, with monad transformers:]

$ darcs get http://samuelhughes.com/darcs/partran/


Is this related in any way to the following GSoC project?

http://code.google.com/soc/2007/haskell/appinfo.html?csaid=B97EF4562EF3B244




No, I just wanted it for my own purposes.

- Sam
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IO within parser

2007-08-12 Thread Sam Hughes

Malte Milatz wrote:
 If not using unsafePerformIO, which is usually not what we want, the
 monad m in question must incorporate IO.  That is, it could be defined
 something like (say we want a parser with state):

newtype IOParser tok s a
= IOParser (s - [tok] - IO (s,a))

 You can then define liftIO without “taking apart” the IO value;
 instead you put liftIO's IO action (IO a) into IOParser's IO action
 (IO (s,a)).  Parsec does not define any such parser, though, so
 there's nothing for which you may define an instance of MonadIO.

 Malte

I'm making (or have made) such a thing, although not necessarily atop 
IO, atop any monad that provides certain stream-like functionality. 
It's kind of done, but not really.


$ darcs get http://samuelhughes.com/darcs/partran/

That is virtually completely untested and has not been proven correct 
either.


Also, whatever documentation there is has probably accidentally been 
copied and pasted from Parsec's (except for the documentation of 
Stream.hs).  Some of the unthinkingly done translations of the files 
found in Parsec's hierarchy seem to be idiomatically immoral.  (Token.hs 
comes to mind.  Something went wrong with functional dependencies and 
avoiding things like breaking the coverage condition/undecidable 
instances and it hurts.  Maybe somebody could tell me what I'm doing 
wrong.)  Also, some functions and definitions of things might be 
appropriately moved around, and you'll probably end up having to import 
more than you'd like to.


Text.ParserCombinators.ParTran.Parsec /might/ currently contain a 
correct simulation of Text.ParserCombinators.Parsec.


- Sam
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe