Re: [Haskell-cafe] Can i split a String by its element ?

2011-02-22 Thread z_axis

:hoogle splitOn
No results found

:m + Data.Text
 splitOn , 2,15,33,0,8,1,16,18

interactive:1:8:
Couldn't match expected type `Text' against inferred type `[Char]`
...

:i splitOn 
splitOn :: Text - Text - [Text]   -- Defined in Data.Text

It seems this splitOn is not one used by you ?


-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Can-i-split-a-String-by-its-element-tp3395066p3396513.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] `cabal install darcs` fail !

2011-02-17 Thread z_axis

cabal update
cabal install darcs
..
Installing library in
/home/sw2wolf/.cabal/lib/hashed-storage-0.5.5/ghc-6.10.4
Registering hashed-storage-0.5.5...
Reading package info from dist/installed-pkg-config ... done.
Writing new package config file... done.
cabal: Error: some packages failed to install:
darcs-2.5.1 depends on haskeline-0.6.3.2 which failed to install.
haskeline-0.6.3.2 failed during the configure step. The exception was:
ExitFailure 1

uname -a
FreeBSD mybsd.zsoft.com 8.1-RELEASE FreeBSD 8.1-RELEASE #1: Wed Sep  8
09:07:54 CST 2010
r...@mybsd.zsoft.com:/media/G/usr/obj/media/G/usr/src/sys/MYKERNEL  i386

It seems that the cabal is NOT very strong, isnot it ?

-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/cabal-install-darcs-fail-tp3390542p3390542.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] The type data constructor confused me !

2011-01-12 Thread z_axis

data Layout a = forall l. (LayoutClass l a, Read (l a)) = Layout (l a)

readsLayout :: Layout a - String - [(Layout a, String)]
readsLayout (Layout l) s = [(Layout (asTypeOf x l), rs) | (x, rs) - reads
s]

Why is the first parameter of readsLayout (Layout l) not Layout (l a) ?

Sincerely!


-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/The-type-data-constructor-confused-me-tp3339226p3339226.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] How to write such a code elegantly ?

2011-01-09 Thread z_axis

betterStdGen :: IO StdGen
betterStdGen = alloca $ \p - do
   h - openBinaryFile /dev/urandom ReadMode
   hGetBuf h p $ sizeOf (undefined :: Int)
   hClose h
   mkStdGen $ peek p

picoSec :: IO Integer
picoSec = do
t - ctPicosec `liftM` (getClockTime = toCalendarTime)
return t

The pseudo-code is :

if doesFileExist /dev/urandom 
then myGen = betterStdGen
else myGen = (mkStdGen . fromTnteger) $ picoSec

How to write these pseudo-code elegantly ?

Sincerely!

-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/How-to-write-such-a-code-elegantly-tp3334329p3334329.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] How to write such a code elegantly ?

2011-01-09 Thread z_axis

thanks for all of your replies.  I will test your code later. Another newbie
question is why has the following code indentation problem ?

rollDice n = do
let myGen =
if doesFileExist /dev/urandom 
then betterStdGen
else (mkStdGen . fromInteger) $ picoSec
return $ (take 1 $ randomRs (1,n) myGen) !! 0


Sincerely!

-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/How-to-write-such-a-code-elegantly-tp3334329p3334379.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] How to write such a code elegantly ?

2011-01-09 Thread z_axis

rollDice n = do 
tmp - doesFileExist /dev/urandom 
myGen - if tmp
then betterStdGen
else (mkStdGen . fromInteger) $ picoSec 

return $ (take 1 $ randomRs (1,n) myGen) !! 0

works but not so elegant?

-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/How-to-write-such-a-code-elegantly-tp3334329p3334395.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] What's the best seed for random API ?

2011-01-05 Thread z_axis

picoSec :: IO Integer
picoSec = do
t - ctPicosec `liftM` (getClockTime = toCalendarTime)
return t

rollDice ::  Int - IO Int
rollDice n = do
ps - picoSec
return $ (take 1 $ randomRs (1,n) $ mkStdGen $ fromInteger ps) !! 0

The above code uses `ctPicosec` as seed. Is it better to use the output of
/dev/urandom as seed ?

Sincerely!

-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/What-s-the-best-seed-for-random-API-tp3329807p3329807.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] cannot install regex-posix using cabal ?

2010-12-15 Thread z_axis

canot it be fixed ?

-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/cannot-install-regex-posix-using-cabal-tp3301201p3307465.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Beginners help

2010-12-15 Thread z_axis

According to map's definition, we know the 'fs' should be a list of function.
so 'p' need a [a-b] as its parameter.And the result of 'p' should be a
list of function which accepts [a] and return [b].

So the type of 'p' is [a-b] - [[a] - [b]]


hope i make it clear.

-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Beginners-help-tp3306796p3307470.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] cannot install regex-posix using cabal ?

2010-12-10 Thread z_axis

%ghc-pkg list|grep -i regex
regex-base-0.93.2

%cabal install regex-posix
Resolving dependencies...
Configuring regex-posix-0.94.4...
Preprocessing library regex-posix-0.94.4...
running dist/build/Text/Regex/Posix/Wrap_hsc_make failed
command was: dist/build/Text/Regex/Posix/Wrap_hsc_make 
dist/build/Text/Regex/Posix/Wrap.hs
cabal: Error: some packages failed to install:
regex-posix-0.94.4 failed during the building phase. The exception was:
ExitFailure 1

How can i fix such a problem ?

-
e^(π.i) + 1 = 0
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/cannot-install-regex-posix-using-cabal-tp3301201p3301201.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] How to use Data.ByteString ?

2009-05-18 Thread z_axis
Hi, friends
the following function works well
rollDice n = getStdRandom (randomR (1,n)) :: IO Int

now i want to use /dev/random to produce better random number, but it doesnot 
work
rollDice_t n = do
hd - openFile /dev/random ReadMode
v -  B.hGet hd 1
return (v `mod` n) + 1

 No instance for (Integral B.ByteString)
  arising from a use of `mod' at Money.hs:15:12-20
Possible fix:
  add an instance declaration for (Integral B.ByteString)
In the first argument of `return', namely `(v `mod` n)'
In the first argument of `(+)', namely `return (v `mod` n)'
In the expression: return (v `mod` n) + 1

then how to use the ByteString properly ?

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


[Haskell-cafe] How to understand the fmap here ?

2009-05-05 Thread z_axis
The following code snippets is from xmonad:
-- Given a window, find the screen it is located on, and compute
-- the geometry of that window wrt. that screen.
floatLocation :: Window - X (ScreenId, W.RationalRect)
--...
rr - snd `fmap` floatLocation w

Prelude :i fmap
class Functor f where fmap :: (a - b) - f a - f b

It seems it is different from the definition of fmap ?
sincerely!

2009-05-05 



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


[Haskell-cafe] about logical computation

2008-09-29 Thread z_axis
hi, friends
I am a Haskell newbie however i like it very much. After starting learn 
haskell, i donot find the corresponding , | , ~, ,  logical 
computation of C language.

Sincerely!  
--
z_axis
2008-09-29


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