Search Results

Search found 4 results on 1 pages for 'pillsy'.

Page 1/1 | 1 

  • Haskell: type inference and function composition

    - by Pillsy
    This question was inspired by this answer to another question, indicating that you can remove every occurrence of an element from a list using a function defined as: removeall = filter . (/=) Working it out with pencil and paper from the types of filter, (/=) and (.), the function has a type of removeall :: (Eq a) => a -> [a] -> [a] which is exactly what you'd expect based on its contract. However, with GHCi 6.6, I get gchi> :t removeall removeall :: Integer -> [Integer] -> [Integer] unless I specify the type explicitly (in which case it works fine). Why is Haskell inferring such a specific type for the function?

    Read the article

  • Parsing and generating JSON

    - by Pillsy
    Mathematica's list of built-in formats is pretty extensive; however, JSON is not on that list. Is there an existing solution for generating and parsing JSON in Mathematica, or are we going to have to roll our own solution?

    Read the article

  • Pointers into elements in a container

    - by Pillsy
    Say I have an object: struct Foo { int bar_; Foo(int bar) bar_(bar) {} }; and I have an STL container that contains Foos, perhaps a vector, and I take // Elsewhere... vector<Foo> vec; vec.push_back(Foo(4)); int *p = &(vec[0].bar_) This is a terrible idea, right? The reason is that vector is going to be storing its elements in a dynamically allocated array somewhere, and eventually, if you add enough elements, it will have to allocate another array, copy over all the elements of the original array, and delete the old array. After that happens, p points to garbage. This is why many operations on a vector will invalidate iterators. It seems like it would be reasonable to assume that an operation that would invalidate iterators from a container will also invalidate pointers to data members of container elements, and that if an operation doesn't invalidate iterators, those pointers will still be safe. However, many reasonable assumptions are false. Is this one of them?

    Read the article

1