[Haskell-cafe] Text.JSON and utf8

2013-02-11 Thread Martin Hilbig

hi,

tl;dr: i propose this patch to Text/JSON/String.hs and would like to
know why it is needed:

@@ -375,7 +375,7 @@
   where
   go s1 =
 case s1 of
-  (x   :xs) | x  '\x20' || x  '\x7e' - '\\' : encControl x (go xs)
+  (x   :xs) | x  '\x20' - '\\' : encControl x (go xs)
   ('' :xs)  - '\\' : ''  : go xs
   ('\\':xs)  - '\\' : '\\' : go xs
   (x   :xs)  - x: go xs


i recently stumbled upon CouchDB telling me i'm sending invalid json.

i basically read lines from a utf8 file with german umlauts and send
them to CouchDB using Text.JSON and Database.CouchDB.

  $ file lines.txt
  lines.txt: UTF-8 Unicode text

lets take 'ö' as an example. i use LANG=de_DE.utf8

ghci tells

 'ö'
'\246'

 putChar '\246'
ö

 putChar 'ö'
ö

 :m + Text.JSON Database.CouchDB
 runCouchDB' $ newNamedDoc (db foo) (doc bar) (showJSON $ 
toJSObject [(test,ö)])

*** Exception: HTTP/1.1 400 Bad Request
Server: CouchDB/1.2.1 (Erlang OTP/R15B03)
Date: Mon, 11 Feb 2013 13:24:49 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 48
Cache-Control: must-revalidate

couchdb log says:

  Invalid JSON: {{error,{10,lexical error: invalid bytes in UTF8 
string.\n}},{\test\:\F6\}}


this is indeed hex ö:

 :m + Numeric
 putChar $ toEnum $ fst $ head $ readHex f6
ö

if i apply the above patch and reinstall JSON and CouchDB the doc
creation works:

 runCouchDB' $ newNamedDoc (db db) (doc foo) (showJSON $ 
toJSObject [(test, ö)])

Right someRev

but i dont get back the ö i expected:

 Just (_,_,x) -runCouchDB' $ getDoc (db foo) (doc bar) :: IO 
(Maybe (Doc,Rev,JSObject String))

 let Ok y = valFromObj test = readJSON x :: Result String
 y
\195\188
 putStrLn y
ü

apperently with curl everything works fine:

$ curl localhost:5984/db/foo -XPUT -d '{test: ö}'
{ok:true,id:foo,rev:someOtherRev}
$ curl localhost:5984/db/foo
{_id:bars,_rev:someOtherRev,test:ö}

so how can i get my precious ö back? what am i doing wrong or does 
Text.JSON need another patch?


another question: why does encControl in Text/JSON/String.hs handle the
cases x  '\x100' and x  '\x1000' even though they can never be
reached with the old predicate in encJSString (x  '\x20')

finally: is '\x7e' the right literal for the job?

thanks for reading

have fun
martin

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


[Haskell-cafe] Hint's setImports usage

2012-12-20 Thread Martin Hilbig

hi,

how to use Language.Haskell.Interpreter.setImports?

i use it like:

  setImports [My.Module]

so that my interpreted modules don't need to:

  import My.Module

But i still get:

  Not in scope: data constructor `MyType'

What am i doing wrong?

Thanks in advance.

have fun
martin

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


Re: [Haskell-cafe] Hint's setImports usage

2012-12-20 Thread Martin Hilbig

ok, i figured it out so far (just after hitting send ;)

'setImports' makes 'My.Modules' stuff available to the interpreted code 
itself (a call to some of my wrapper functions) but not to my module 
My.Interpreted.Module where which i use via


  setTopLevelModule [My.Interpreted.Module]

So i guess there is no way to add the import to the 
'My.Interpreted.Module' for convenience.


Sorry for the noise.

have fun
martin

On 21.12.2012 00:35, Martin Hilbig wrote:

hi,

how to use Language.Haskell.Interpreter.setImports?

i use it like:

   setImports [My.Module]

so that my interpreted modules don't need to:

   import My.Module

But i still get:

   Not in scope: data constructor `MyType'

What am i doing wrong?

Thanks in advance.

have fun
martin

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


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


Re: [Haskell-cafe] Hint's setImports usage

2012-12-20 Thread Martin Hilbig

oh that's neat!

but what to do if MyPrelude is provided by some package?

i get this error:

  module `MyPrelude' is a package module

and neither

  set [languageExtensions := [PackageImports]]

nor

  {-# LANGUAGE PackageImports #-}

helps.

have fun
martin

On 21.12.2012 00:55, Michael Sloan wrote:

Hello!

Try doing this first:

   loadModules [My.Module]

You may also need to set the searchPath - it defaults to the current
director.  Another good function to know about is setTopLevelModules,
which is just like using :load in ghci - it imports everything in the
module, including its imports.  So, I often do:

   loadModules [MyPrelude]
   setTopLevelModules [MyPrelude]

And stick all of the things that I want to be in scope into MyPrelude.hs.

-Michael


On Thu, Dec 20, 2012 at 3:35 PM, Martin Hilbig li...@mhilbig.de
mailto:li...@mhilbig.de wrote:

hi,

how to use Language.Haskell.Interpreter.__setImports?

i use it like:

   setImports [My.Module]

so that my interpreted modules don't need to:

   import My.Module

But i still get:

   Not in scope: data constructor `MyType'

What am i doing wrong?

Thanks in advance.

have fun
martin

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




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


Re: [Haskell-cafe] Hint's setImports usage

2012-12-20 Thread Martin Hilbig

On 21.12.2012 01:23, Michael Sloan wrote:

Yeah, I've run into that too..

It does seem like there ought to be a better way, but in order to get
around that, I just define the imports (or generate) MyPrelude.hs in
the current directory.


what do you do with the file then? neither loadModules, setImports,
setTopLevelModules helped me :/

have fun
martin


That file can just consist of import
OtherPackage.MyPrelude.

-Michael


On Thu, Dec 20, 2012 at 4:12 PM, Martin Hilbig li...@mhilbig.de
mailto:li...@mhilbig.de wrote:

oh that's neat!

but what to do if MyPrelude is provided by some package?

i get this error:

   module `MyPrelude' is a package module

and neither

   set [languageExtensions := [PackageImports]]

nor

   {-# LANGUAGE PackageImports #-}

helps.

have fun
martin


On 21.12.2012 00:55, Michael Sloan wrote:

Hello!

Try doing this first:

loadModules [My.Module]

You may also need to set the searchPath - it defaults to the
current
director.  Another good function to know about is
setTopLevelModules,
which is just like using :load in ghci - it imports everything
in the
module, including its imports.  So, I often do:

loadModules [MyPrelude]
setTopLevelModules [MyPrelude]

And stick all of the things that I want to be in scope into
MyPrelude.hs.

-Michael


On Thu, Dec 20, 2012 at 3:35 PM, Martin Hilbig li...@mhilbig.de
mailto:li...@mhilbig.de
mailto:li...@mhilbig.de mailto:li...@mhilbig.de wrote:

 hi,

 how to use Language.Haskell.Interpreter.setImports?


 i use it like:

setImports [My.Module]

 so that my interpreted modules don't need to:

import My.Module

 But i still get:

Not in scope: data constructor `MyType'

 What am i doing wrong?

 Thanks in advance.

 have fun
 martin

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





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


[Haskell-cafe] How to use Jacobian from levmar lib?

2012-05-15 Thread Martin Hilbig

hi,

i'm using the nice levmar package like this [1].

why is there such a big difference in 'infNorm2E' between using/not 
using the Jacobian?


thanks in advance
martin hilbig

[1]: http://hpaste.org/68537

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


Re: [Haskell-cafe] Database.CouchDB broken?

2010-07-31 Thread Martin Hilbig

hi,

try it this way:

http://gist.github.com/501951

note the type annotations and the added req param include_docs=true for
getAllDocs.

the first error is created by ghci, since it dont know the specific type

Database.CouchDB :t runCouchDB' $ getDoc (db test) (doc xyz) 
runCouchDB' $ getDoc (db test) (doc xyz)

  :: (JSON a) = IO (Maybe (Doc, Rev, a))

but why doesnt it complain about the ambiguous type variable `a', like
in `read 124`?

the addition of the include_docs=true request parameter really should be
in the getAllDocs function itself.

i'll fix this and put it in my own haskell-couchdb repo, as well as the
simple bulk and attachment apis i implemented, stay tuned ;)

have fun
martin

On 19.07.2010 19:08, Moritz Ulrich wrote:

Hello,

I'm currently learning Haskell and I want to write a small tool to
collect some data in a CouchDB-Database Sadly, the Database.CouchDB
module from hackage (and from git) seems broken. It looks like a bug
 deep in the JSON handling of the lib.

Some examples can be found in this gist:
http://gist.github.com/475323 ('test' is a database with two simple
documents, the doc with the id '8e9112011580882422393f6291000f7d'
exists)

I filed an issue, but the maintainer hasn't responded in 5 days. Is
there anything I missed?

Thanks in advance!


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


Re: [Haskell-cafe] Re: Hot-Swap with Haskell

2010-07-16 Thread Martin Hilbig

hi,

if been thinking about an haskell interpreter to, because of erlang's 
otp. its syntax is a mess, but its scalability is win.


since erlang runs in its vm (interpreted) is there a need for a real 
haskell interpreter, or can there be a compiled haskell/otp with 
hotswapping, scaling and stuff?


now back on topic, i wrote real haskell interpreter because there is 
the hint[1] package, which wrappes the ghc api.


now i dont know what more the plugin package provides, but i thought 
hint is like is successor (since lambdabot used plugins and now uses 
mueval, which in turn uses hint ;). please correct me.


have fun
martin

[1]: http://hackage.haskell.org/package/hint

On 16.07.2010 06:06, Andy Stewart wrote:

Don Stewartd...@galois.com  writes:


lazycat.manatee:

Hi all,

I'm research to build a hot-swap Haskell program to developing itself in
Runtime, like Emacs.

Essentially, Yi/Xmonad/dyre solution is replace currently executing
technology:

re-compile new code with new binary entry

when re-compile success
   $ do
   save state before re-launch new entry
   replace current entry with new binary entry (executeFile)
   store state after re-launch new entry

There are some problems with re-compile solution:

1) You can't save *all* state with some FFI code, such as gtk2hs, you
can't save state of GTK+ widget. You will lost some state after
re-launch new entry.

2) Sometimes re-execute is un-acceptable, example, you running some command
in temrinal before you re-compile, you need re-execute command to
restore state after re-launch, in this situation re-execute command is 
un-acceptable.

I wonder have a better way that hot-swapping new code without
re-compile/reboot.



Well, the other approach to reloadable modules, using either object code
plugins, or bytecode plugins, giving you module-level granularity.

Thanks for your reply.

I have read your papers : Dynamic Application From the Group Up and  Plugging 
Haskell In

In Dynamic Application From the Group Up, you introduction how to use
re-compile technology implement source-code level hot-swapping.

In Plugging Haskell In, you introduction to how to buld hot-swapping
with object-code level.

Yes, Dynamic linking can add new code to a running program, but how to
replace existing binding with new ones?
Looks you still need some reboot when you do *replace* and not just *add*.

Infact, reboot is okay, only problem is *keep state*, some *static state*
is easier to re-build, example, if you want restore editor buffer state, you
just need save (filepath, cursorPosition), you can re-open file and
restore cursor position after reboot process.

Difficult is *Stream State*, such as:
   delete operation in file-manager
   command running in temrinal
   network communications in browser
It's really difficult to restore those state, and re-execute is
un-acceptable sometimes.

You can found the screenshot of my project at 
http://www.flickr.com/photos/48809...@n02/

Currently, the closest library to implement dynamic linking is your
plugins package (http://hackage.haskell.org/package/plugins-1.4.1),
i really want to write some code to test it, unfortunately, it's
broken with Cabal-1.8.0.4 that can't compile with ghc-6.12.x/ghc-6.12.3,
can you fix it if you have time? It's so great package...

I'm looking for some paper about Haskell and hot-swapping.
Any paper or suggestion are welcome!

   -- Andy





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

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


Re: [Haskell-cafe] Re: ANNOUNCE: fgl-5.4.2.3

2010-07-12 Thread Martin Hilbig

On 12.07.2010 09:25, Ivan Lazar Miljenovic wrote:

A couple of points I meant to make here but forgot (I was busy hacking
on this and my other three graph-related packages for over a week now,
and especially this past weekend it cut into my sleeping...):

* Apart from bug-fixes, I don't intend on touching the 5.4 series any
   more.  That said, I believe that this version is suitable for
   replacing 5.4.2.2 in the platform (what's the process on that?).

* After I get my generic graph class sorted out at AusHac this coming
   weekend, I intend to make a 5.5.0.0 release which extends the classes
   in this new library; this will probably _not_ be suitable for the
   platform and is intended to serve as a stepping stone to the
   replacement library Thomas Bereknyei and I are working on.

With that last point: Thomas and I are willing to call this new
version/replacement something like inductive-graphs if that is the
preference of the community.  Does anyone know of a website that would
let us have a survey we can use to determine which option people would
prefer?


how about http://doodle.com?

have fun, keep hacking.
martin


 Note that even if we give it a new name (rather than just a new
major version number), we still intend on using the Data.Graph.Inductive
module namespace (as it makes even more sense with the new name), so
there will still be clashes between this new version and fgl.

Ivan Lazar Miljenovicivan.miljeno...@gmail.com  writes:


I'm pleased to present the first new release of fgl [1] since Thomas
Bereknyei took over maintaining it from Martin Erwig.

[1] http://hackage.haskell.org/package/fgl

Before people start panicking, rioting, etc., please check the version
number: this is just a bug-fix release, and not the complete re-write
version which we've been talking about (since we got a little
sidetracked, etc.).  As such, the API hasn't changed, and this should
fit right in to packages already using fgl (sorry to all those people
who followed my advice and put fgl == 5.4.2.2 in the build-depends
fields of their packages' .cabal files, but I didn't expect to make
another 5.4.y release).

The exact change that has been made is to fix a bug pointed out to me by
Tristan Allwood, in that Data.Graph.Inductive.PatriciaTree didn't
support multiple edges (and furthermore this wasn't specified in the
documentation).  This has now been rectified.  As an indication of what
these changes mean, see this sample call graph produced by my
SourceGraph program; when using PatriciaTree from fgl-5.4.2.2 the lines
were all the same thickness; now there is among other things a loop of
width 32 on getExp and a line of width 7 from getExp to maybeEnt.



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


Re: [Haskell-cafe] GHCi and State

2010-06-28 Thread Martin Hilbig

hi,

On 25.06.2010 11:07, corentin.dup...@ext.mpsa.com wrote:



Another couple of reflexions (sorry for monopolizing):

1. Since i am making a Nomic game, players will have to submit rules. These
rules will be written in a sub-set of haskell.
Instead of writing my own reader/interpreter, i'd like to use GHC to compil
them on the fly, and then add them to the current legislation.
What would you suggest me to do that? Any pointers?


check out hint, a nice wrapper around the ghc api [1].

have fun
martin

[1]: http://hackage.haskell.org/package/hint


2. For now, the game is more or less playable in GHCi. But my concern is:
When you use GHCi, you are in the IO monad, right? How to had state to this
monad?
I would like that the player can compose his rule in GHCi, and when he is
done, he can submit it in GHCi with something like:

*Nomic  submitRulemyrule

And then the game takes the rule, possibly modify the current legislation,
and give the hand back to GHCi.
So the current legislation has to be a state of the GHCi's loop. Is this
possible at all?
submitRule would have a type more or less like that (GameState contains the
legislation):

submitRule :: Rule -  StateT GameState IO ()


Thanks for  your attention! I know this is a bit confused!

Best,
Corentin


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

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


Re: [Haskell-cafe] making the GHC Api not write to stderr

2010-05-20 Thread Martin Hilbig

hi,

i tried this too, but i did not get it. a very nice workaround is to use 
hint [1].


have fun
martin

[1]: http://hackage.haskell.org/package/hint

On 20.05.2010 20:05, Phyx wrote:

I was wondering how to forcibly quiet down the API. I have a custom
handler in place, but when I call the function on failure both my
handler gets called and somewhere somehow errors get printed to the
stderr, which I really need to avoid.

My current code looks like

getModInfo :: Bool - String - String - IO (ApiResults ModuleInfo)

getModInfo qual file path = handleSourceError processErrors $

runGhc (Just libdir) $ do

dflags - getSessionDynFlags

setSessionDynFlags $ configureDynFlags dflags

target - guessTarget file Nothing

addTarget target

setSessionDynFlags $ dflags { importPaths = [path] }

load LoadAllTargets

graph - depanal [] False

let modifier = moduleName . ms_mod

modName = modifier $ head graph

includes = includePaths dflags

imports = importPaths dflags

dflags' - Debug.trace (moduleNameString modName) getSessionDynFlags

setSessionDynFlags $ dflags' { includePaths = path:includes

, importPaths = path:imports

}

parsed - parse modName

checked - typecheckModule parsed



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

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


[Haskell-cafe] corner case in Text.JSON 0.4.3

2010-05-12 Thread Martin Hilbig

hi,

since i got no answer from the maintainer, maybe someone else can take 
care of it, or at least point out, what i did wrong.


so, i recently stumbled upon some error while using Text.JSON 0.4.3 [1]:

  Text/JSON/String.hs:(127,4)-(137,49): Non-exhaustive patterns in case

indeed ghc warned:

  [5 of 7] Compiling Text.JSON.String ( Text/JSON/String.hs, 
dist/build/Text/JSON/String.o )


  Text/JSON/String.hs:127:4:
  Warning: Pattern match(es) are non-exhaustive
   In a case alternative: Patterns not matched: []

from looking at the code i couldn't see how this would ever happen, but 
you can reproduce it be running the files from [2]:


  $ ./test  problem
  Ok (JSArray [JSString (JSONString {fromJSString = this}),JSString 
(JSONString {fromJSString = is}),JSString (JSONString {fromJSString = 
some}),JSString (JSONString {fromJSString = json}),JSObject 
(JSONObject {fromJSObject = [(that,JSString (JSONString {fromJSString 
= works}))]})])

test: Text/JSON/String.hs:(127,4)-(137,49): Non-exhaustive patterns in case

the patch i put there fixes it (at least for me) to return an Error 
instead of dying:


  $ ./test  problem
  Ok (JSArray [JSString (JSONString {fromJSString = this}),JSString 
(JSONString {fromJSString = is}),JSString (JSONString {fromJSString = 
some}),JSString (JSONString {fromJSString = json}),JSObject 
(JSONObject {fromJSObject = [(that,JSString (JSONString {fromJSString 
= works}))]})])

  Error Unexpected end of String: does
  Error Malformed JSON: invalid token in this context not\]
  test: stdin: hGetLine: end of file

have fun
martin hilbig

[1]: http://hackage.haskell.org/package/json
[2]: http://friendpaste.com/3IvnChRMoczf0mIKpOtrYE
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] redirecting ghc (as a library) output

2010-02-27 Thread Martin Hilbig

hi, i'm writing a Haskell View Server for CouchDB.

it communicates with couchdb over stdin and stdout. it gets JSON encoded 
haskell code, compiles it (like on 
http://www.haskell.org/haskellwiki/GHC/As_a_library), gets values, runs 
the given code over the given values and writes the results back (also 
json encoded).


when there is an error in the given haskell code it should reply with 
the error json encoded and exit. but f.e. when the given code imports a 
module, which cannot be found (here Reaction) ghc just spits out a panic 
directly to stdin and exits like this:


 ViewServer: panic! (the 'impossible' happened)
   (GHC version 6.12.1 for x86_64-unknown-linux):
 Could not find module `Reaction':
   Use -v to see a list of the files searched for.


 Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

it puts other errors directly to stdout too, like:

 Assembler messages:
 Fatal error: can't create
 /home/*/AlkylRadicalDecomposition.o:
 Permission denied

this confuses couchdb, because it expects some JSON and i cant see whats 
going on between them.


now, how can i prevent ghc from using stdout and wrap the output in some 
JSON? is this even possible?


with ghc 6.10 this usage of 'handle' worked for me:

 main = handle (\e - do
let e' = show (e::SomeException)
case fromException e of
  Just UserInterrupt - exitSuccess
  _ - do
  let err = error2json the impossible happened... e'
  putStrLn err
  logToFile err
  return []) main_loop

did i got the Exception handling wrong?

thanks in advance.

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