newtype PCRE = PCRE (Ptr PCRE)
The example I provided reduces to:
newtype XEvent = XEvent (Ptr XEvent). -- a recursive newtype that cannot be dereferenced
In summary:
1. This pattern can be use to specify the types just for type-checking within Haskell. They do not contain any data. Therefore, not data can be cerated for XEvent.
2. Data can be created for type `Ptr XEvent` using the `alloca` interface, and only way to de-reference these values would be through `peek`. But, while derefencing the resulting values will have other types.
Next, I plan to spend some time working on these examples to get a better sense.
Thank you all!
The meaning of XEvent is different on the left and right sides of the newtype declaration. On the left, it's a type; on the right, it's a data constructor. The constructor wraps a value which refers to the type, but not recursively back to the constructor itself.On Tue, Nov 6, 2018, 8:36 AM Guru Devanla <gurudev.devanla@gmail.com wrote:_______________________________________________Hello Haskell-Cafe,I have been recently studying the XMonad code and some related types available in the X11 bindings library.I came across this type:newtype XEvent = XEvent XEventPtrAvailable here:It seems that this type is circular here. how does one use this type? Is it possible to create a value out of this type? What is the use of this type?Please could someone help me wrap my head around this?Thanks
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.