[Haskell-cafe] FFI binding -- different behaviour under compilation and interpretation.

Jason Dusek jason.dusek at gmail.com
Sat Nov 14 00:26:05 EST 2009


  There is a Cabal package for this already:

    http://hackage.haskell.org/package/setlocale

  A call to `setLocale LC_ALL (Just "")` in `main` fixes things.

--
Jason Dusek



2009/11/13 Daniel Fischer <daniel.is.fischer at web.de>:
> Am Samstag 14 November 2009 00:00:36 schrieb Jason Dusek:
>>   I'm binding to `wcwidth` to determine the column widths of
>>   various Unicode characters. I noticed a lot of -- in fact all
>>   -- Chinese characters were being given widths of `-1` when of
>>   course they should have width `2`. This only showed up when I
>>   compiled my program though -- within GHCi, it never happened.
>
> It seems that ghci calls setlocale(LC_ALL,"") or similar, while the compiled code doesn't.
> I've no idea why that would be, but
>
> dafis at linux-mkk1:~/Haskell/CafeTesting> cat locl.h
> void sloc();
> dafis at linux-mkk1:~/Haskell/CafeTesting> cat locl.c
> #include <locale.h>
> #include "locl.h"
>
> void sloc(){
>    setlocale(LC_ALL,"");
> }
>
>
> main                         =  do
>  setloc
>   (sequence_ . fmap (UTF8.putStrLn . uncurry fmt)) widths
>    where...
>
> foreign import ccall unsafe "locl.h sloc" setloc :: IO ()
>
> fixes it.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list