newbie question how to pass data

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

newbie question how to pass data

Mujtaba Boori
Hello

I am sorry for the silly question. 

I have a function as the following

func:: ((Float,Float) ->Bool) -> Float -> ((Float,Float) -> Bool)

I am trying to make calculation in this type ((Float,Float) ->Bool)  with Float and then pass the information to ((Float,Float) -> Bool)


Thank again appreciated. 

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: newbie question how to pass data

Ozgur Akgun
Can you at least give an example of how you intend to use this "func"?
Since you do not describe it's behaviour, it is very hard to make a useful
comment (at least for me)

Best,

On 19 April 2010 16:54, Mujtaba Boori <[hidden email]> wrote:

>
> Hello
> I am sorry for the silly question.
>
> I have a function as the following
> func:: ((Float,Float) ->Bool) -> Float -> ((Float,Float) -> Bool)
> I am trying to make calculation in this type ((Float,Float) ->Bool)  with Float and then pass the information to ((Float,Float) -> Bool)
>
> Thank again appreciated.
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



--
Ozgur Akgun
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: newbie question how to pass data

Mujtaba Boori
sorry 

ok I am trying to make these calculation 

func  (x,y) s dg  =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg)))

This work for type (Float -> Float)

but how can make it work with ((Float -> Float) -> Bool)

because my main function that I want use with.  it takes (Float,Float) ->Bool)  I need to return the same type ((Float,Float) ->Bool)  so it could be used with other function. 


On Mon, Apr 19, 2010 at 5:54 PM, Ozgur Akgun <[hidden email]> wrote:
Can you at least give an example of how you intend to use this "func"?
Since you do not describe it's behaviour, it is very hard to make a useful
comment (at least for me)

Best,

On 19 April 2010 16:54, Mujtaba Boori <[hidden email]> wrote:
>
> Hello
> I am sorry for the silly question.
>
> I have a function as the following
> func:: ((Float,Float) ->Bool) -> Float -> ((Float,Float) -> Bool)
> I am trying to make calculation in this type ((Float,Float) ->Bool)  with Float and then pass the information to ((Float,Float) -> Bool)
>
> Thank again appreciated.
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



--
Ozgur Akgun



--
Mujtaba Ali Alboori

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: newbie question how to pass data

Dan Weston
First of all, your function
func  (x,y) s dg  =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg)))
does NOT work for type (Float -> Float), unless you mean that that is
the type of the unused parameter s. Also, your desired type ((Float ->
Float) -> Bool) itself looks suspicious. It must accept any function
(without something to apply it to) and arbitrarily return True or False.
How will you decide which? I suspect you need another parameter for this
function.

Second, on the off chance you are trying to calculate the position on a
circle scaled then rotated an angle dg from (x,y), that new position is

f (x,y) s dg = (s*(x*(cos dg) - y*(sin dg)),s*(x*(sin dg) + y*(cos dg)))

in which case you are missing the s and the last minus sign in your
formula should be a plus sign.
If so, this can be evaluated with greater clarity (and probably
accuracy) in polar coordinates:

g (x,y) s dg = (r * cos a, r * sin a)
   where r  = s * sqrt (x^2 + y^2)
            a  = atan2 y x + dg

Third, if you did not need the scale, I would use an underscore to make
that clear:

h (x,y) _ dg = (r * cos a, r * sin a)
   where r  = sqrt (x^2 + y^2)
            a  = atan2 y x + dg

That's all the observations I can make unless you describe the problem
more clearly. Sorry.

Dan

Mujtaba Boori wrote:

> sorry
>
> ok I am trying to make these calculation
>
> func  (x,y) s dg  =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg)))
>
> This work for type (Float -> Float)
>
> but how can make it work with ((Float -> Float) -> Bool)
>
> because my main function that I want use with.  it takes (Float,Float)
> ->Bool)  I need to return the same type ((Float,Float) ->Bool)  so it
> could be used with other function.
>
>
> On Mon, Apr 19, 2010 at 5:54 PM, Ozgur Akgun <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Can you at least give an example of how you intend to use this "func"?
>     Since you do not describe it's behaviour, it is very hard to make a
>     useful
>     comment (at least for me)
>
>     Best,
>
>     On 19 April 2010 16:54, Mujtaba Boori <[hidden email]
>     <mailto:[hidden email]>> wrote:
>      >
>      > Hello
>      > I am sorry for the silly question.
>      >
>      > I have a function as the following
>      > func:: ((Float,Float) ->Bool) -> Float -> ((Float,Float) -> Bool)
>      > I am trying to make calculation in this type ((Float,Float)
>     ->Bool)  with Float and then pass the information to ((Float,Float)
>     -> Bool)
>      >
>      > Thank again appreciated.
>      > _______________________________________________
>      > Haskell-Cafe mailing list
>      > [hidden email] <mailto:[hidden email]>
>      > http://www.haskell.org/mailman/listinfo/haskell-cafe
>      >
>
>
>
>     --
>     Ozgur Akgun
>
>
>
>
> --
> Mujtaba Ali Alboori
>

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: newbie question how to pass data

Mujtaba Boori
Thanks Dan. Great help 

but my problem has not solved yet
This doesn't work for type ((Float -> Float)->Bool)

to make it easier ignore the rotation and suppose I want just multiplay with whatever (x ,y) and return the result to this type ((Float -> Float)->Bool)

note this type is shorten and replace by t
Type Point = (Float, Float)
Type Bitmap = Point -> Bool

so the function type actually
func :: Bitmap -> Float -> Bitmap

I want to take Bitmap do some calculation on Bitmap  the return it as Bitmap.

GHCi response for Dan method is this 
    Couldn't match expected type `Bitmap'
           against inferred type `(a, b)'
so it is missing a Bool.

hopefully it is clear .

On Mon, Apr 19, 2010 at 7:02 PM, Dan Weston <[hidden email]> wrote:
First of all, your function 


  

func  (x,y) s dg  =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg)))
does NOT work for type (Float -> Float), unless you mean that that is the type of the unused parameter s. Also, your desired type ((Float -> Float) -> Bool) itself looks suspicious. It must accept any function (without something to apply it to) and arbitrarily return True or False. How will you decide which? I suspect you need another parameter for this function.

Second, on the off chance you are trying to calculate the position on a circle scaled then rotated an angle dg from (x,y), that new position is

f (x,y) s dg = (s*(x*(cos dg) - y*(sin dg)),s*(x*(sin dg) + y*(cos dg)))

in which case you are missing the s and the last minus sign in your formula should be a plus sign.
If so, this can be evaluated with greater clarity (and probably accuracy) in polar coordinates:

g (x,y) s dg = (r * cos a, r * sin a)
 where r  = s * sqrt (x^2 + y^2)
          a  = atan2 y x + dg

Third, if you did not need the scale, I would use an underscore to make that clear:

h (x,y) _ dg = (r * cos a, r * sin a)
 where r  = sqrt (x^2 + y^2)
          a  = atan2 y x + dg

That's all the observations I can make unless you describe the problem more clearly. Sorry.

Dan

Mujtaba Boori wrote:
sorry
ok I am trying to make these calculation
func  (x,y) s dg  =((x*(cos dg) - y*(sin dg)),(x*(sin dg) - y*(cos dg)))

This work for type (Float -> Float)

but how can make it work with ((Float -> Float) -> Bool)

because my main function that I want use with.  it takes (Float,Float) ->Bool)  I need to return the same type ((Float,Float) ->Bool)  so it could be used with other function.

On Mon, Apr 19, 2010 at 5:54 PM, Ozgur Akgun <[hidden email] <mailto:[hidden email]>> wrote:

   Can you at least give an example of how you intend to use this "func"?
   Since you do not describe it's behaviour, it is very hard to make a
   useful
   comment (at least for me)

   Best,

   On 19 April 2010 16:54, Mujtaba Boori <[hidden email]
   <mailto:[hidden email]>> wrote:
    >
    > Hello
    > I am sorry for the silly question.
    >
    > I have a function as the following
    > func:: ((Float,Float) ->Bool) -> Float -> ((Float,Float) -> Bool)
    > I am trying to make calculation in this type ((Float,Float)
   ->Bool)  with Float and then pass the information to ((Float,Float)
   -> Bool)
    >
    > Thank again appreciated.
    > _______________________________________________
    > Haskell-Cafe mailing list
    > [hidden email] <mailto:[hidden email]>

    > http://www.haskell.org/mailman/listinfo/haskell-cafe
    >



   --
   Ozgur Akgun




--
Mujtaba Ali Alboori




--
Mujtaba Ali Alboori

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: newbie question how to pass data

Stephen Tetley-2
Hi

If you are working with characteristic functions (Point -> Bool or
Point -> Colour...) the common way to do this is to manufacture a Num
instance for functions. This gives you syntax overloading of the (+,
-, *) operators. Similarly you might want to overload (or have to
overload) Floating, Fractional...

Examples using this technique are Jerzy Karczmarczuk's Clastic, Conal
Elliott's Vertigo, Tangible Values, Pan etc.

To overload Num you have to define Show and Eq instances for functions
as well. Something along the lines of this is adequate:

type CF = (Double,Double) -> Bool

instance Show CF where
  show _ = "<function>"

instance Eq CF where
 (==) _ _ = error "No Eq on  Characteristic functions"

instance Num CF where
  f + g = \pt -> f pt + g pt
  -- ...
  negate f = \(x,y) -> f (negate x, negate y)

  -- ... rest follows this pattern, Floating, Fractional similar

If you characteristic function is Point -> Bool then you also need a
Num instance for Bool.

All that said, I think your formulation of func above is slightly
wrong to fit this style. Its forming a function (-> Point) "to point"
rather than a characteristic function Point -> Bool.

Best wishes

Stephen
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: newbie question how to pass data

Mujtaba Boori
Great job Stephen.
Thank for explaining . I got it to work.


On Tue, Apr 20, 2010 at 9:21 AM, Stephen Tetley <[hidden email]> wrote:
Hi

If you are working with characteristic functions (Point -> Bool or
Point -> Colour...) the common way to do this is to manufacture a Num
instance for functions. This gives you syntax overloading of the (+,
-, *) operators. Similarly you might want to overload (or have to
overload) Floating, Fractional...

Examples using this technique are Jerzy Karczmarczuk's Clastic, Conal
Elliott's Vertigo, Tangible Values, Pan etc.

To overload Num you have to define Show and Eq instances for functions
as well. Something along the lines of this is adequate:

type CF = (Double,Double) -> Bool

instance Show CF where
 show _ = "<function>"

instance Eq CF where
 (==) _ _ = error "No Eq on  Characteristic functions"

instance Num CF where
 f + g = \pt -> f pt + g pt
 -- ...
 negate f = \(x,y) -> f (negate x, negate y)

 -- ... rest follows this pattern, Floating, Fractional similar

If you characteristic function is Point -> Bool then you also need a
Num instance for Bool.

All that said, I think your formulation of func above is slightly
wrong to fit this style. Its forming a function (-> Point) "to point"
rather than a characteristic function Point -> Bool.

Best wishes

Stephen
_______________________________________________
Haskell-Cafe mailing list
[hidden email]



--
Mujtaba Ali Alboori

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe