Re: [Haskell-cafe] Getting segmentation fault when profiling, despite `-K100M'.

2011-08-16 Thread Christopher Wilson
On Tue, Aug 16, 2011 at 12:42 PM, Niklas Larsson metanik...@gmail.com wrote:
 If you want to call a Haskell function from C you should do a foreign
 export of the function, that will create a stub function with C
 calling convention that you can call.


I put an example of how to do this on Rosetta Code:

http://rosettacode.org/wiki/Use_another_language_to_call_a_function#Haskell

-- 
Chris Wilson christopher.j.wil...@gmail.com

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


Re: [Haskell-cafe] Why is Haskell flagging this?

2010-12-18 Thread Christopher Wilson
On Fri, Dec 17, 2010 at 11:04 AM, michael rice nowg...@yahoo.com wrote:

 I don't understand this error message. Haskell appears not to understand
 that 1 is a Num.

 Prelude :t 1
 1 :: (Num t) = t
 Prelude :t [1,2,3,4,5]
 [1,2,3,4,5] :: (Num t) = [t]
 Prelude

 Michael

 ===

 f :: [Int] - IO [Int]
 f lst = do return lst

 main = do let lst = f [1,2,3,4,5]
   fmap (+1) lst

 ===

 Prelude :l test
 [1 of 1] Compiling Main ( test.hs, interpreted )

 test.hs:5:17:
 No instance for (Num [Int])
   arising from the literal `1' at test.hs:5:17
 Possible fix: add an instance declaration for (Num [Int])
 In the second argument of `(+)', namely `1'
 In the first argument of `fmap', namely `(+ 1)'
 In the expression: fmap (+ 1) lst
 Failed, modules loaded: none.
 Prelude


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


Excuse any inaccuracies, I'm somewhat new at Haskell myself, but what it
looks like is happening is that at the point in main where you've bound
lst, it will have type of IO [Int].  The signature for fmap is:

fmap :: (Functor f) = (a - b) - f a - f b

if you call fmap (+1) the next argument that fmap expects is something
that is in just one functor, for example, this

fmap (+1) [1,2,3,4,5]

works fine, but, something that is IO [Int] won't.  You can compose two
'fmap's to solve this:

:t (fmap.fmap)
(fmap.fmap)
  :: (Functor f, Functor f1) = (a - b) - f (f1 a) - f (f1 b)

which means that 'main' looks like:


main = do let lst = f [1, 2, 3, 4, 5]
  (fmap.fmap) (+1) lst


-- 
Chris Wilson christopher.j.wil...@gmail.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe