News aggregator

Proposal: Improve error messages for (!!) (include index and length of list)

libraries list - Thu, 10/16/2014 - 7:20am
Hi, currently we have the following implementation for (!!): #ifdef USE_REPORT_PRELUDE xs !! n | n < 0 = error "Prelude.!!: negative index" [] !! _ = error "Prelude.!!: index too large" (x:_) !! 0 = x (_:xs) !! n = xs !! (n-1) #else -- HBC version (stolen), then unboxified xs !! (I# n0) | isTrue# (n0 <# 0#) = error "Prelude.(!!): negative index\n" | otherwise = sub xs n0 where sub :: [a] -> Int# -> a sub [] _ = error "Prelude.(!!): index too large\n" sub (y:ys) n = if isTrue# (n ==# 0#) then y else sub ys (n -# 1#) #endif I propose to change the error messages for the non-report version to include index and list length, something that is functionally equivalent to: xs !! (I# n0) | i
Categories: Offsite Discussion

Splicing type signature in TH

haskell-cafe - Thu, 10/16/2014 - 5:06am
Hi list, I am 99.9% sure that this is currently not possible, but I might as well ask: - Is there a way to lift type variables into Template Haskell type splices? What I had in mind would be something like this (erroneous) code: liftT :: a -> Q Type liftT (_::a) = [t| $a |] I have no idea how hard it would be to implement such a feature, or if it is remotely doable. Naively, it seems to me that TH would have to delay evaluating the splice until the type variable is fully expanded, but all the necessary information would still be available at some point during compilation. Cheers, hugo
Categories: Offsite Discussion

C structures in Haskell FFI

Haskell on Reddit - Thu, 10/16/2014 - 2:11am
Categories: Incoming News

Newbie haskell question

Haskell on Reddit - Wed, 10/15/2014 - 9:34pm

I have a list (rs) of lists of length 4 with integers from 0..7, I would like a function to return a list of length 8 that has at each index the number of times said integers appear...

This seems awfully simple but I can't do shit... All I can think of is concatenating the list but then I don't know how to even proceed. I keep thinking of just iterating over arrays and adding state...

[i | i <- concat rs ]

submitted by AceCream
[link] [6 comments]
Categories: Incoming News

Unicode symbols in operators

haskell-cafe - Wed, 10/15/2014 - 8:23pm
(I'm trying to improve Sublime Text's Haskell lexer.) says uniSymbol → any Unicode symbol or punctuation What is meant here, is "Unicode symbol" literally \p{Symbol} in regex, or more? So uniSymbol = \p{Symbol} | \p{Punctuation} Thanks! _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

Trying to understand monad transformers: state in an IO loop

Haskell on Reddit - Wed, 10/15/2014 - 7:45pm

I'm trying to implement a loop that prints an integer timer value from getPOSIXTime. This is my first attempt at composing monads and I'm fresh from completing LYAH (which didn't go into transformers, I have looked at a few resources on transformers but most of the examples are too complex for me to follow or weren't specific to IO + State).

I have about 40 lines of code here that I've managed to at least get the type checker to accept, but I'm not getting any output to the console:

module Timer ( runTimer ) where import Control.Monad import Control.Monad.State import Data.Time.Clock.POSIX import Data.Int type ClockTime = Int64 posixToClockTime :: POSIXTime -> ClockTime posixToClockTime x = floor $ (read $ init $ show x) * 1000 curTime :: IO ClockTime curTime = posixToClockTime `fmap` getPOSIXTime newTime :: ClockTime -> State ClockTime Bool newTime newtime = state $ \oldtime -> if (oldtime < newtime) then (True, newtime) else (False, oldtime) runTimer :: StateT ClockTime IO () runTimer = forever $ do newtime <- lift curTime oldtime <- get let (b,_) = runState (newTime newtime) oldtime if (b == True) then lift $ putStrLn $ show newtime else do return ()

Ideally runTimer would loop and print the timestamp when it has changed, otherwise doing nothing.

I can call return runTimer from a GHCi prompt, but nothing is output and it returns immediately.

Basically, is there a way to get this to run or am I barking up the wrong tree?

submitted by D_duck
[link] [8 comments]
Categories: Incoming News

question about using read and map

Haskell on Reddit - Wed, 10/15/2014 - 6:52pm

Hi, i have a list like ["5","4"] and i would like to use the function read to get the value of each elements in my list

i know that i can do

read "5" :: Int

but how can i apply that for an entire list?

I was thinking about using map like

map read ["5","4"] :: Int


map read ["5"::Int, "4":: Int]

but it does not work as far as i can tell.

Any help would be nice, sorry for the newbie question ^

submitted by superancetre
[link] [4 comments]
Categories: Incoming News

Ask /r/haskell: Should I be signing up / getting involved with the libraries mailing list?

Haskell on Reddit - Wed, 10/15/2014 - 4:57pm

(This is partly a genuine question, but there's also a bit of musing in amongst it)

I've known about the existence of the libraries mailing list for a while, and thought it might be something I'd sign up for at some point in the future.

The discussion around adding Foldable and Traversable to the Prelude - and the fact that it was a surprise to a lot of folks - got me thinking that I should probably sign up in order to keep up with these kind of changes / get a chance to have my say if I spot a problem with a proposal.

Does anyone on or familiar with the list know if it's the kind of list where casual, non-expert users are useful rather than background noise? Or am I conflating the libraries committee and the libraries mailing list?

On one hand, I wouldn't want to be a (potential) distraction.

On the other hand, I want to get in there to keep an eye on what is being proposed, mostly out of curiosity.

I also want to get in there for statistical reasons - I figure having more people active on the list might help with the mandate / marketing of the decisions the library committee makes.

Of course, that would fall to bits if the distribution of people for or against a proposal was correlated with the distribution of people too busy to sign up to another mailing list :)

Any info or thoughts would be appreciated.

submitted by dalaing
[link] [2 comments]
Categories: Incoming News

Deriving vs. type constructors

haskell-cafe - Wed, 10/15/2014 - 3:55pm
I'm struggling with a problem related to generic programming, boiling down to this: ----snip---- {-# LANGUAGE StandaloneDeriving, KindSignatures, UndecidableInstances #-} data Foo (v :: * -> *) = Foo (v Bar) deriving instance (Show (v Bar)) => Show (Foo v) data Bar = Bar deriving Show ----snip---- So the Show instance for Foo v wants the rather specific Show instance for v Bar. But now imagine that v is always something like Maybe, itself done using something like this presumably: instance Show a => Show (Maybe a) where ... Can I somehow state as a constraint that Foo v has a Show instance if v is a type constructor like Maybe, i.e. once with a Show instances for any arguments that has a Show instance? (You can't see *why* I want to do this in this example - I actually have something like 100 nested datatypes which thread v through, and *every single one of them* adds to the context I need for every one of them.) I feel I want to write something like this: deriving instance (Show a => Show (v a
Categories: Offsite Discussion

Optimizing Haskell games with minimal changes.

haskell-cafe - Wed, 10/15/2014 - 3:43pm
Hi Café, As you know, we are building Android games in Haskell, and efficiency is crucial. I often find myself trying to explain to other game programmers that the price to be paid in speed in exchange for the robustness and the clarity of the language is minimal; and that optimising and parallelising can be very easy. In our game we only had to apply very basic techniques (RWH, Chapter 25; Parallel & Concurrent Haskell, Chapter 2) to obtain a x7 speedup and reduce memory consumption from hundreds to 3MB on desktop. The number of changes to the codebase was minimal. I hope it helps support the case that using Haskell even for CPU demanding code is worth it. Our game now also runs smoothly on Android. Hopefully this will also help others trying to achieve the same thing. Cheers Ivan
Categories: Offsite Discussion

Missing or undocumented ARM architecture controls

haskell-cafe - Wed, 10/15/2014 - 3:23pm
I worked around a problem of a build of a simple cross ghc not finding (shared) libraries by setting the LIBRARY_PATH environment variable. Not ideal. Then I came to a problem with StcCRun.c using vldmia and related instructions which are part of ARMv6. I worked around this by putting #defines for arm_HOST_ARCH_PRE_ARMv6 and arm_HOST_ARCH_PRE_ARMv7 in mk/config.h Now it seems to make use of llvm at a later stage and that fails with "inplace/bin/ghc-stage1" -static -H64m -O0 -Iincludes -Iincludes/dist -Iincludes/dist-derivedconstants/header -Iincludes/dist-ghcconstants/header -Irts -Irts/dist/build -DCOMPILING_RTS -package-name rts -dcmm-lint -i -irts -irts/dist/build -irts/dist/build/autogen -Irts/dist/build -Irts/dist/build/autogen -O2 -c rts/Exception.cmm -o rts/dist/build/Exception.o '+v7' is not a recognized feature for this target (ignoring feature) UNREACHABLE executed! UNREACHABLE executed! Stack dump: 0. Program arguments: /usr/bin/llc -O3 -relocation-model=static /tmp/ghc2
Categories: Offsite Discussion