Questions tagged [coerce]

73 questions
5
votes
2 answers

Is there a standard Haskell function with type: (Floating a, RealFrac b) => a -> b?

I need to call floor() on a value, which is only constrained to be of class Floating, but floor() requires RealFrac. How can I do this? I'm perfectly willing to call abs() before calling floor(), but this alone seems insufficient to solve my…
dbanas
  • 1,707
  • 14
  • 24
5
votes
1 answer

How to use Types::Path::Tiny with Moo

My first question on this site, I come quickly. I'm a developer, I mainly use Python and Perl. I am passionate and I really like the development. My first question is about Perl, Moo, and Type::Tiny. Type::Tiny is a great module for use with Moo of…
Hobbestigrou
  • 1,777
  • 1
  • 13
  • 16
4
votes
1 answer

Problem coercing a record with complex type parameters

I have this record: import Data.Functor.Identity import Control.Monad.Trans.Identity import Data.Coerce data Env m = Env { logger :: String -> m () } env :: Env IO env = undefined and this coercion function decorate :: Coercible…
danidiaz
  • 26,936
  • 4
  • 45
  • 95
3
votes
4 answers

Unexpected behavior of coerce inside foldMap's callback

This code compiles: import Data.List (isPrefixOf) import Data.Monoid (Any(..)) import Data.Coerce isRoot :: String -> Bool isRoot path = getAny $ foldMap (coerce . isPrefixOf) ["src", "lib"] $ path I'm using coerce as a shortcut for wrapping the…
danidiaz
  • 26,936
  • 4
  • 45
  • 95
3
votes
2 answers

Converting dgCMatrix to logical matrix

Consider this simple sparse matrix > (X <- sparseMatrix(c(1, 2, 1), c(1, 1, 2), x = 0:2)) 2 x 2 sparse Matrix of class "dgCMatrix" [1,] 0 2 [2,] 1 . How can I convert it into a matrix indicating if the corresponding element is non-empty? Here is…
nalzok
  • 14,965
  • 21
  • 72
  • 139
3
votes
2 answers

Error in OpenNLP package - dataframe coercing

I am trying to run a basic sentence annotation function and I keep running into the same error. The code I tried to use is: s <- as.String(cleandata) #cleandata is my data.It is a character class. sent_ann <- Maxent_Sent_Token_Annotator() a2 <-…
3
votes
2 answers

Why doesn't `Range#cover?` raise an exception when comparison fails?

Given that Time objects cannot be compared with Fixnum without explicit casting: 0 <= Time.now # => ArgumentError: comparison of Fixnum with Time failed Time.now <= 10000000000 # => ArgumentError: comparison of Time with 10000000000 failed and what…
sawa
  • 165,429
  • 45
  • 277
  • 381
3
votes
1 answer

Unexpected Numpy / Py3k coercion rules

I was looking for a bug in a program, and I discovered that it was produced by an unexpected behavior from Numpy... When doing, e.g., a simple arithmetic operation on different integer types using Python3k and Numpy, like (numpy.uint64) + (int) the…
Koren
  • 51
  • 3
2
votes
2 answers

Coercing from Arrays

Suppose I have this simple class: class Color attr_accessor :rgb def initialize(ary) @rgb = ary end def +(other) other = Color.new(other) unless Color === other Color.new(@rgb.zip(other.rgb).map {|p| [p.reduce(:+), 255].min }) …
Guilherme Bernal
  • 8,183
  • 25
  • 43
2
votes
2 answers

Can not deduce proper type when coercing newtype

I was trying to simplify my life with newtype with coerce, but I've encountered a quite painful problem when using it in certain scenario: import Data.Coerce (coerce) import Data.Foldable (toList) -- | newtype instance wrapping foldable type (not…
majkrzak
  • 1,332
  • 3
  • 14
  • 30
2
votes
1 answer

How to set up an AoArrayrefs attribute with coercion from scalar into arrayref?

I would like to set up an attribute that is an array of arrayrefs with coercion of nonarrayrefs to array refs. eg. [ 0, [ 0, 0, 0 ], [1,2,3] ] into [ [0], [ 0, 0, 0 ], [1,2,3] ] also, I'd like to be able to push or set elements to the AoA with…
Demian
  • 215
  • 2
  • 9
1
vote
1 answer

Lisp Coerce and Set function explanation

I try to do this directly to the interpret: (setf example (coerce "blablabla" 'list)) and works fine. Infact (car example) returns #\b but if I try this: (defun myfun (string) ( (setf example (coerce string 'list)))) (myfun "blablabla") I don't…
marchetto91
  • 135
  • 9
1
vote
1 answer

cassandra-cli: unable to coerce 'allias' to version 1 UUID

I'm triyng to create a column family with TimeUUIDType as name of row: create column family users with column_type = 'Standard' and comparator = 'TimeUUIDType' and default_validation_class = 'UTF8Type' and key_validation_class = 'UTF8Type' and…
Undrooleek
  • 223
  • 4
  • 12
1
vote
0 answers

Error in as.data.frame.default(x[[i]], optional = TRUE): cannot coerce class ‘"function"’ to a data.frame

I am trying to make a c chart to analyse new diagnoses but I can't get past this stage. Please see code below: Error in as.data.frame.default(x[[i]], optional = TRUE): cannot coerce class ‘"function"’ to a data.frame Traceback: qic(x = col_date, y…
1
vote
2 answers

How to convert an AppleScript URL object to text

I have a URL object in AppleScript, and I'm trying to convert it to a text object. set theURL to "http://apple.com/myfile" as URL --set t to theURL as text --Fails, can't coerce to text set a to scheme of theURL --works set b to host of theURL…
Jesse Barnum
  • 6,507
  • 6
  • 40
  • 69